Use on clause to compare values from join clause in CSharp

Description

The following code shows how to use on clause to compare values from join clause.

Example


using System;// w w w . j  av a  2 s.  c  o m
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


public class MainClass{

   public static void Main(string[] args){   
            Int32[] ArrayA = { 1, 2, 3, 4, 8 };
            Int32[] ArrayB = { 1, 3, 5, 7, 8 };

            var Joined = from QueryA in ArrayA
                         join QueryB in ArrayB
                         on QueryA equals QueryB
                         select new { QueryA, QueryB };


            foreach (var OutPair in Joined)
                Console.WriteLine(OutPair.QueryA.ToString() + " - " + OutPair.QueryB.ToString());


   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    LINQ »




Operator
Select
Where
OrderBy
Group
Join
Let
LINQ