• Home
  • About
  •  

    LINQ - Where Operator


    This blog is not updated anymore.
    I am now writing at my new site One .Net Way

    “Where” operator is the most commonly used LINQ operator. For those familiar with SQL “Where” operator will be obvious. It filters the results based on specified criteria. Below is an example using a list of cities.

    List<string> cities =
      new List<string> { 
        “New York”, 
        “Sydney”, 
        “Paris”, 
        “New Delhi” };
    
    
     
    var result = 
      from c in cities
      where c.StartsWith(“New”)
      select c;
     
    foreach (string item in result)
    {
      Console.WriteLine(item);
    }

    Here we used the where operator to select cities which start with “New”. Below is the output:

    image

    Technorati Tags:

    You may also like to read...

    Leave a Reply