Chaining Query Operators/extracts all strings containing the letter "a", sorts them by length, and then converts the results to uppercase : Query « LINQ « C# / C Sharp






Chaining Query Operators/extracts all strings containing the letter "a", sorts them by length, and then converts the results to uppercase

 

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

class LinqDemo {
    static void Main() {
        string[] names = { "J", "P", "G", "P" };

        IEnumerable<string> query = names
          .Where(n => n.Contains("a"))
          .OrderBy(n => n.Length)
          .Select(n => n.ToUpper());

        foreach (string name in query) Console.Write(name + "|");
    }
}

 








Related examples in the same category

1.Use Contains, Length and ToUpper from Linq
2.Use select to retrieve all nodes in a Binary tree
3.Get Distinct departments with condition
4.Use LINQ to get Employees in the IT department from a tree
5.Use from where select to choose the Employees in the IT department from a tree
6.All employees in a tree are grouped by department