C# Program to Check a Specified City Exists in the List Collection Using LINQ

C# Program to Check a Specified City Exists in the List Collection Using LINQ Article has many meanings. We are going to know this topic clearly through this article. We hope you like this article.

C# Program to Check a Specified City Exists in the List Collection Using LINQ

C# Program to Check a Specified City Exists in the List Collection Using LINQ

//C# program to check specified city exists 
//in the List Collection using Linq.

using System;
using System.Collections.Generic;
using System.Linq;

class LinqDemo
{
    static void Main(string[] args)
    {
        List<string> listCity = new List<string>() { "Delhi", "Mumbai", "Agra", "Gwalior", "Jhashi" };

        string city = "Agra";
        bool isExist = false;
        
        isExist = listCity.AsEnumerable().Contains(city);

        if (isExist == true)
            Console.WriteLine(city + " city exists in List");
        else
            Console.WriteLine(city + " city does not exists in List");
    }
}
Agra city exists in List
Press any key to continue . . .

Final Words

C# Program to Check a Specified City Exists in the List Collection Using LINQ We got to know our topic very clearly. And if you have any doubts about this article you can let us know your doubts via comment.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment