Answers for "c# count specific element in list"

C#
1

c# count specific element in list

// lstSlots = new List<int> { 1, 1, 0 }
lstSlots.Count(n => n == 1)	// returns 2
Posted by: Guest on September-08-2021
-1

get count of specific objects in list c#

var myList = new List<int>()
{
  0, 1, 2, 1, 5, 4, 8, 5, 2, 7, 1, 9
};

int count = 0;
foreach (var number in list)
{
  if (number == 2)
    count++;
}

Console.WriteLine("Number of 2s in list is: " + count);
// Output:
// Number of 2s in list is: 2
Posted by: Guest on December-13-2020

Code answers related to "c# count specific element in list"

C# Answers by Framework

Browse Popular Code Answers by Language