简体   繁体   中英

Find number of elements in array matching query

I have the following class:

public class Words
{
    public string word;
    public bool correct;
}

and I have an array of Words.

Words[] words;

I wish to count how many elements in my array have the property correct set to true.

What would be the most efficient way to do this?

Using LINQ

words.Where(w=>w.correct);

That should do the trick to filter.


But if you only want to count:

words.Count(w=>w.correct);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM