How to check if an element exists in a list with C#

1 Answer

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

class Program {
   static void Main(string[] args) {
      List<string> list = new List<string>() { "c#", "java", "c", "python", "c++", "rust" };
   
      bool exists = list.Exists(e => e.Equals("java"));
   
      if (exists) {
         Console.WriteLine("Exists");
      }
      else {
         Console.WriteLine("Not exist");
      }
   }
}



/*
run:

Exists

*/

 



answered Mar 30, 2024 by avibootz

Related questions

2 answers 154 views
2 answers 231 views
1 answer 171 views
171 views asked Jul 5, 2021 by avibootz
3 answers 227 views
2 answers 238 views
2 answers 159 views
...