Here is an example of an array, showing some common LINQ operations.
Copy Code code as follows:
static void Main (string[] args)
{
Int[] A = {1, 2, 3, 4, 5, 6, 7};
Int[] B = {4, 5, 6, 7, 8, 9, 10};
Int[] C = {1, 2, 3, 3, 4, 1, 2, 4, 6, 1, 6, 5};
Intersection
var fuck = A.intersect (b);
and set
var shit = a.union (b);
A There's no B.
var diff1 = a.except (b);
b there's a No.
var diff2 = b.except (a);
var max = A.max ();
var min = a.min ();
var avg = A.average ();
var dis = c.distinct ();
Print (Fuck);
Print (shit);
Print (diff1);
Print (DIFF2);
Console.WriteLine (max);
Console.WriteLine (min);
Console.WriteLine (avg);
Print (DIS);
Console.readkey ();
}
private static void Print (Ienumerable<int> list)
{
foreach (var item in list)
{
Console.Write (item + "");
}
Console.WriteLine ();
}
There is a picture of the truth:
Some references:
Http://msdn.microsoft.com/zh-cn/library/bb397894.aspx
Http://msdn.microsoft.com/en-us/library/system.linq.enumerable.intersect.aspx