In the development process, array and set processing are the most worrying. for or foreach is generally used to process some operations. Here we will introduce some common set and array operation functions.
First, we will give an example of two sets, A and 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); sets. B merge List <int> Result = listA. union (listB ). toList <int> (); // remove duplicate items List <int> Result = listA. concat (listB ). toList <int> (); // retained duplicate items
ListA. BinarySearch ("1"); // determines whether a value is included in the set. If yes, 0 is returned.
In the 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 (); merge Arrays
Int [] x = I. Union (j). ToArray <int> (); // remove duplicate items
Int [] x = I. Concat (j). ToArray <int> (); // retained duplicate items
Int n = Array. BinarySearch (I, 3); // determines whether the Array contains a value. If it contains, 0 is returned.