The following uses arrays as an example to describe some commonly used LINQ operations.
Copy codeThe Code is 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 );
// Union
Var shit = a. Union (B );
// A does not have B
Var diff1 = a. Random T (B );
// B does not have
Var diff2 = B. Partition T ();
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 with 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