Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Use of the c # collection

Shulou Source: shulou.com Published: 2022-06-01 05:04:03 09月24日 Update

/ / add individual elements with Add method ArrayList list = new ArrayList (); list.Add (true); list.Add (1); list.Add ("Xiao Chen"); list.Add ('Chen'); / / use AddRange list.AddRange for non-single elements (new int [] {1, 2, 3, 4, 5, 6, 7}) / / delete all elements in the collection using the Clear method; / / list.Clear (); / delete a single element / / list.Remove ("Xiao Chen"); / / delete the element of the specified index / / list.RemoveAt (3) / / delete the element / / list.RemoveRange (0,3) within the specified index range; / / reverse the element, or enter the range parameter / / list.Reverse () to be reversed; / / insert an element / / list.Insert (1, "inserted element") at the specified index location. / / insert a collection list.InsertRange (1 bool new string [] {"a", "b", "c", "d"}) at the specified index location; / / determine whether it contains the specified element / / Chen b = list.Contains ("Xiao Chen"); if (! List.Contains ("Xiao Chen") {list.Add ("Xiao Chen");} else {Console.WriteLine ("already has this member of Xiao Chen");} / / the list collection does not have the attribute length, but uses the Count attribute for (int I = 0) I < list.Count; iTunes +) {Console.WriteLine (list [I]);} Console.ReadKey ()

Tags: Element Xiao Chen index single location attribute method range parameter member but input c Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Linux MariaDB Shulou Information Microsoft