C# Find object inside List object -


this question has answer here:

what trying is, find object inside list

log q = logs.find(x => (x.dnsq.queryid.contains(queryid))); 

however when it, error

x.dnsq.queryid = 'x.dnsq.queryid' threw exception of type 'system.nullreferenceexception

the log class looks this

class log : logctrl {     public int id { set; get; }     public string source { set; get; }     public string destination { set; get; }     public string protocol { set; get; }     public double time { set; get; }     public string info { set; get; }     public dnsresponse dnsr { set; get; }     public dnsquery dnsq { set; get; } } 

it sounds either x or x.dnsq or x.dnsq.queryid null @ least 1 item in logs. can check in statement doing following:

    log q = logs.find(x => (x != null && x.dnsq != null && x.dnsq.queryid != null && x.dnsq.queryid.contains(queryid))); 

Comments