Compare value from two from clause in CSharp

Description

The following code shows how to compare value from two from clause.

Example


 /*  w  w w .ja  v  a 2 s.  c o  m*/
 
 
  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {

        int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
        int[] numbersB = { 1, 3, 5, 7, 8 };

        var pairs =
            from a in numbersA
            from b in numbersB
            where a < b
            select new { a, b };

        Console.WriteLine("Pairs where a < b:");
        foreach (var pair in pairs) {
            Console.WriteLine("{0} is less than {1}", pair.a, pair.b);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ