use variable within a linq query

Posted by jstawski on Stack Overflow See other posts from Stack Overflow or by jstawski
Published on 2010-04-13T16:06:15Z Indexed on 2010/04/13 16:13 UTC
Read the original article Hit count: 310

Filed under:
|

take this linq into consideration:

list.Where(sil => sil.XML.Element("ticket") != null && sil.XML.Element("ticket").Attribute("id").Value == smsRequestIn.TicketID)

if the "ticket" element is not null it searches for it twice and hence is not very effective. Is there a way to use some sort of variables within the linq expression so I can reference the variable instead of doing a double search for the "ticket" element or is linq intelligent enough to not do a double search?

© Stack Overflow or respective owner

Related posts about .net-3.5

Related posts about LINQ