Query with an Exception

image_pdfimage_print
   
 


using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] presidents = {"AAAA", "aaaa", "bacDert", "B1234", "Carter"};

        IEnumerable<string> items = presidents.Where(s => Char.IsLower(s[4]));

        Console.WriteLine("After the query.");

        foreach (string item in items)
            Console.WriteLine(item);

    }
}

    


Use string method in where clause

image_pdfimage_print
   
 


using System;
using System.Linq;

public class MainClass {
    public static void Main() {
        string[] greetings = { "hello world", "hello LINQ", "hello" };

        var items =
         from s in greetings
         where s.EndsWith("LINQ")
         select s;

        foreach (var item in items)
            Console.WriteLine(item);
    }
}

    


To remove all vowels from a string.

image_pdfimage_print
   
 

using System;
using System.Collections.Generic;
using System.Linq;
public class MainClass {
    public static void Main() {

        IEnumerable<char> query = "Not what you might expect";

        query = query.Where(c => c != &#039;a&#039;);
        query = query.Where(c => c != &#039;e&#039;);
        query = query.Where(c => c != &#039;i&#039;);
        query = query.Where(c => c != &#039;o&#039;);
        query = query.Where(c => c != &#039;u&#039;);

        foreach (char c in query) Console.Write(c); 
    }
}

    


A Query Using the Standard Dot Notation Syntax

image_pdfimage_print
   
 


using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {

        string[] names = { "A1", "B123", "C123123", "E", "W" };

        IEnumerable<string> sequence = names
         .Where(n => n.Length < 6)
         .Select(n => n);

        foreach (string name in sequence) {
            Console.WriteLine("{0}", name);
        }
    }
}

    


Query Using the Query Expression Syntax

image_pdfimage_print

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
public static void Main() {

string[] names = { “A123123”, “B123”, “C123123”, “E123”, “W” };
IEnumerable sequence = from n in names
where n.Length < 6 select n; foreach (string name in sequence) { Console.WriteLine("{0}", name); } } } [/csharp]

Where Prototype

image_pdfimage_print
   
 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] presidents = {"A", "Ar", "B", "Bu", "C", "Cleveland"};

        IEnumerable<string> sequence = presidents.Where(p => p.StartsWith("C"));

        foreach (string s in sequence)
            Console.WriteLine("{0}", s);

    }
}