The following example returns the number of elements present in the collection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp17 { class Program { static void Main(string[] args) { int[] intNumbers = new int[] { 60, 80, 50, 90, 10, 30, 70, 40, 20, 100 }; //Using Method Syntax int MSCount = intNumbers.Count(); //Using Query Syntax var QSCount = (from num in intNumbers select num).Count(); Console.WriteLine("Number of Elements = " + MSCount); Console.ReadKey(); } } } |
Output: Number of Elements = 10