How to find out an Element in a C# list

Now we are going to learn about how we can find out an element in C# list.
  • 4437

Introduction

To find out an element in a list is very easy process, we will check each and every element in a list for a certain value. When an element is match then it produce as a output. This process is passively by the foreach loop.

Example

class Program
{
static void Main()
{
List<int> primes = new List<int>(new int[] { 10, 4, 16 });
foreach (int number in primes){
if (number == 4)
{
Console.WriteLine("Contains 4");
Console.Read();
}
}
}
}
}

Output

findlist.jpg

© 2013 dotNetheaven. All rights reserved.