Where() function:
How to remove empty strings from an array?
I was having a string array like
string[] arrNames = { "315", "610", "1", "13", "456" };
First I was following the same loop approach for removing empty string from a string array. But then I used Where() function and by using it my code change to
arrNames = arrNames.Where(name => !string.IsNullOrEmpty(name)).ToArray();
Count() function:
How to count number of true values in an array?
I was having a boolean array like
bool[] arrAnswerChoices = { true, false, true, true, false, true };
I wanted to know how many true values are present in the array. Then I came to know the powerfulness of count() function and used it as follows:
arrAnswerChoices.Count(choice => (choice));
The above code gave me the number of true values present in the boolean array, using arrAnswerChoices.Count(choice => (!choice)); will give the number of false values present in the array.
Hope this helps you