I am writing a LINQ query which has a sort of subquery. It looks like this:
var x = from p in pc
let Cntrs = p.GetCounters().Where(args => args.CounterName == CounterName)
select Cntrs;
Cntrs is a PerformanceCounter object. However, the intellisense returns it as a collection with collection methods.
I don’t see the properties such as NextValue, etc (which is what I want).
What am I missing? Also, and I know this must have been asked before, what’s the difference between the let and into keywords?
Thanks
This means that the
Wheremethod is returning more than one instance, in other words you have more than one counter whose name equals the value of yourCounterNamevariable.If you don’t care which one you get you can use the
FirstOrDefaultextension method to retrieve the first item from the sequence that is being returned from theWherelike this: