How to check if a list contains a value in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

            bool b = list.Contains<int>(3);
            if (b)
                Console.WriteLine("yes");

            if (list.Contains(10))
                Console.WriteLine("yes");
        }
    }
}


/*
run:
     
yes
yes
 
*/

 



answered Feb 21, 2017 by avibootz
...