Basic Linq Filtering query


I would like to share a simple basic link query using  the extension method Where():
Assume that we have a console application opened in Visual Studio the code that filters the array of string using Linq approach should look like as the code below:
    public class Program
      static void Main(string[] args)
        string[] animals = new string[] { "Dog", "Monkey",
            "Spider", "Wombat", "Snake", "Emi", "Shark",
            "Sting-Ray", "Jellyfish" };

        var q = animals.Where(
                a => a.StartsWith("D") && a.Length > 2);
        foreach (string s in q)

If you run the code in Visual Studio you should get the result that I’ve got on the screenshot:





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s