How can I count elements that are equal to 0 in each array of a list?
I have a list List<byte[]> piks.
I would like to count in each byte[] how many elements are with equal to 0.
I tried a few ways:
from c in piksle_lista_tablic[84]
where (c.Equals(0))
select c
or
piksle_lista_tablic[84].Count(n => n == 0)
and I always get the error Expression cannot contain lambda expressions.
For example:
piks[1] is an array containing 1156 items, and I would like to know how many specific elements are in that array.
PS: Can i use Linq in watch window?
var results = from arr in piks
select arr.Where(b=>b==0).Count()
that code will iterate the list of array and for each array find the elements equalling zero and return an IEnumerable with the counts for each array. I like the where count more than the Count(selector) but that a matter of taste. I doubt there's going to be noticeable difference performancewise
to you ps 1 yes you can use linq while debugging but it's generally a pain because a linq statement is one statement chopping it up in methods can sometimes help while debugging but I dislike writing code for the sake of the debugger.
EDIT As per your comment: No you cannot use Lambda in the watch window. You can use Linq in the watch window but only as method calls and only with named functions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With