How to check if a list contains specific value using Linq in C#

1 Answer

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

class Program
{
    static void Main() {
        var list = new List<int> { 3, 5, 1, 7, 6, 8 };

        bool result = list.Contains(7);

        if (result) {
            Console.WriteLine("yes");
        }
    }
}
   
   
   
   
/*
run:
      
yes
    
*/

 



answered Jul 6, 2023 by avibootz
...