C # Operations on multiple collections and arrays (merging, de-weighing, judging)

Source: Internet
Author: User

During the development process. The handling of arrays and collections is the most worrying. Some operations are typically handled with a for or foreach. Here are some commonly used sets and arrays of operation functions.

First, for example, 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); Merges the collection a.b list<int> Result = lista.union (LISTB).          Tolist<int> (); Reject duplicates list<int> Result = Lista.concat (LISTB).        Tolist<int> (); Keep Duplicates

Lista.binarysearch ("1");//Determines whether a value is included in the collection. Returns 0 if included

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> (); Reject Duplicates

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

int n = array.binarysearch (i,3);//Determines whether a value is included in the array. Returns 0 if included

C # Operations on multiple collections and arrays (merging, de-weighing, judging)

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.