linq Count
linq Count
public static void Count() { // linq Count - Simple int[] factorsOf300 = { 2, 2, 3, 5, 5 }; int uniqueFactors = factorsOf300.Distinct().Count(); Console.WriteLine("There are {0} unique factors of 300.", uniqueFactors); // linq Count - Conditional int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; int oddNumbers = numbers.Count(n => n % 2 == 1); Console.WriteLine("There are {0} odd numbers in the list.", oddNumbers); }
Output
linq Count
Reviewed by Bhaumik Patel
on
6:52 PM
Rating: