C # generic collection of - list

List base

 

  1. Overview List: list of hash set differs in that its elements can be repeated. (Closer to the logic array, and hash set closer to the set of mathematical)
  2. Create and initialize:

 

        (1) List <type> name list = new List <type> ();

 

        (2) List <type> name list = new List <type> () {value};

 

        (3) List <type> name list = new List <type> (array name);

 

  3. Basic operation:

 

      (1) add a single element: .Add list name (the additive element);

 

      (2) adding a plurality of elements: list name .AddRange (the name of the array elements are added);

 

      (3) Insert an element: .Insert list name (parameter a: insertion position, two parameters: the element to be inserted); // // 1 starts from the insertion position can traverse foreach

 

      (4) into a group of elements: list name .InsertRang (a parameter: the insertion position, the array);

 

      (5) To delete an element: List the name .Remove (element); // Note If there are multiple elements of the same values, delete only the first

 

      (6) removes an element by index: a list of names .RemoveAt (superscript elements);

 

      (7) Remove the plurality of index elements by: list name .RemoveRange (a parameter: where to begin, two parameters: the number)

 

      (8) list can be called with a list of elements name [subscript], but not hash set.

 

      (9) to determine whether an element in the list: a list of names .Contains (element);

 

      (10) to sort the elements in the list by the first letter: l: List the name .Sort (); reverse: a list of names .Reverse (); // not drop

 

      (11) Clear the list of all the elements: a list of names .Clear ();

 

      The number (12) Gets a list of elements: .Count list name ();

 

      (13) a digital type capable of performing mathematical maximum, minimum, sum, average value.

 

      (14) will be copied to the list of elements in an array: list name .CopyTo (array name);

 

      (15) A copy of the list element in an array: the array name = name list .toArray ();

 

  4. Advanced Operation:

 

      (1) find a list of all the elements that satisfy the condition: Note that the return value is still a list of

 

        List <Type> new list name = name .findall old list (delegate function (here returns BOOL value));

 

          bool delegate the function name (parameter list element type)

 

            {I.e. parameter list represents each element, this makes a conditional judgment, note that the return value of type bool} // lambda expression can also be used

 

      (2) all other list elements satisfy the condition: return value is a list of still, the logic (1) opposite

 

        List <Type> new list name = name of the old list .RmoveAll (delegate function (here returns BOOL value));

 

      (3) return back past the first qualifying list elements:

 

             Returns the element list type variable name = name list .Find (delegate function or lambda expression); // FindLast Find and use the same, just looking from back to front

 

      (4) obtaining a first n rows of the list element value:

 

        IEnumetable <Type> new list name = name of the old list .Take (first n elements); // prefix Note

 

      (5) List.Where and List.Findall similar except that the return type is still IEnumetable

 

      (6) determining whether all elements of the list of matches: bool return value type

 

         bool mark = list name .TrueForAll (delegate function or lambda expression);

 

Guess you like

Origin www.cnblogs.com/fangexuxiehuihuang/p/11620840.html