C # _c# tutorial on how to manipulate multiple sets and arrays (merging, going heavy, judging)

Source: Internet
Author: User
Tags arrays

In the development process. The handling of arrays and collections is the most worrying. You typically use a for or foreach to handle some operations. Here are some commonly used sets and arrays of operation functions.

First, an example of 2 sets a,b.

list<int> lista = new list<int> {1,2,3,5,7,9};

list<int> Listb = new list<int> {13,4,17,29,2};

Lista.addrange (LISTB); Merge the collection a.b

list<int> result = Lista.union (LISTB). Tolist<int> (); Remove Duplicates

list<int> result = Lista.concat (LISTB). Tolist<int> (); Keep Duplicates

Lista.binarysearch ("1"); Determines whether a value is contained in the collection. If included then return 0

In an example of two arrays

Int[] I=new int[]{1,2};
Int[] J=new int[]{2,3};
list<int> r = new list<int> ();
R.addrange (i);

R.addrange (j);
Int[] C = R.toarray (); Merging arrays

Int[] X=i.union (j). Toarray<int> (); Remove Duplicates

Int[] X=i.concat (j). Toarray<int> (); Keep Duplicates

int n = array.binarysearch (i,3);//Determine if a value is contained in the array. If included then return 0

The above C # for a number of sets and arrays of operation methods (merger, go to weight, judgment) is a small set to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.

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.