Compare value from two different int arrays in where clause in CSharp

Description

The following code shows how to compare value from two different int arrays in where clause.

Example


     /* www . jav a 2s .c  o  m*/
using System;
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 TwoFroms = from QueryA in ArrayA
                           from QueryB in ArrayB
                           where QueryA == QueryB
                           select new { QueryA, QueryB };

            foreach (var OutPair in TwoFroms)
                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