LINQ C# Book

A subquery is a query contained in another query's lambda expression.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java a", "C# c", "Javascript t" };
IEnumerable query = names.OrderBy(m => m.Split().Last());
foreach (string s in query)
{
Console.WriteLine(s);
}
}
}

The output:
Java a
C# c
Javascript t
Get all strings with the shortest length:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java", "C#", "Javascript" };
IEnumerable outerQuery = names
.Where(n => n.Length == names.OrderBy(n2 => n2.Length)
.Select(n2 => n2.Length).First());

foreach (string s in outerQuery)
{
Console.WriteLine(s);
}
}
}
The output:
C#
Here's the same thing as a query expression:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string[] names = { "Java", "C#", "Javascript" };
IEnumerable outerQuery =
from n in names
where n.Length == (from n2 in names orderby n2.Length select n2.Length).First()
select n;
foreach(string s in outerQuery){
Console.WriteLine(s);
}
}
}

The output:
C#