c# - Confusion over storing a type in a temp variable in a LINQ query -


I am writing a LINQ query that looks like a subquarium:

  Var x = p to pc let cntrs = p.getcounters (). Select Cntrs (args = & gt; argsCounterName == countername);  

Although Cntrs is a PerformanceCounter object, intellisense gives it as a collection with collection methods.

I do not see the properties like NextValue, etc. (which I want).

What am I missing? Apart from this, and I know what should be asked before, what is the difference between going to keywords and in the middle?

Thanks

This means that where method More than one example is returning, in other words, you have more than one counter, whose name is your CounterName variable.

If you do not care which one has been received from you, you can use the FirstOrDefault extension method to obtain the item before that sequence That where is like this:

  var x = p to pc let cntrs = p.getcounters (). Where (args => argsCounterName == CounterName). FirstOrDefault () Select Cntrs;  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -