LINQ operation Array code (intersection, and set, difference set, maximum value, average, go repeat) _ Practical tips

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.