User1 User1 - 1 year ago 137
C# Question

LINQ: Where on select result?

Is it somehow possible to use variant abc without having to call Convert twice ? I mean like def, but without a second from ?

Something like:

var desired = (from x in AnswerRecords
select Converter(x) as bla
where bla != null

Answer Source

Your case fits exactly the use of the let keyword. Check SO Documentation: Defining a variable inside a Linq query (let keyword)

Use it to store the result of the Converter and then check it:

var result = from item in AnswerRecords
             let converted = Converter(item)
             where converted != null
             select converted;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download