"Learning Notes" C # ArrayList

Source: Internet
Author: User

  • Collection
    • A collection is a container in which you use collective management-related groups of objects
    • Collections are divided into non-generic collections and generic collections
  • Non-generic collection
    • Using a non-generic collection requires the introduction of a namespace System.Collections
    • arraylist-arrays that can be dynamically added as needed
    • hashtable-hash table used to store key-value pairs
    • Queue-follows the FIFO queue
    • Stack-follows a last-in-first-out stack
  • Generic collection
    • Using generic collections requires the introduction of namespaces System.Collections.Generic
    • list<t>-arrays that can be dynamically added as needed
    • Dictionart<tkey, tvalue>-hash table used to store key-value pairs
    • Queue<t>-follows the FIFO queue
    • Stack<t>-follows a last-in-first-out stack
  • ArrayList
    • ArrayList is a special array.
    • You can dynamically change the length of an array by adding or removing elements
    • Flexibility to insert, delete, and access elements
    • is not a strong type, slower than a normal array
  •       
    1 usingSystem;2 //using a non-generic collection requires the introduction of namespaces3 usingSystem.Collections;4 5 namespaceArraylistdemo6 {7     class Program8     {9          Public Static voidLog (ArrayList arr)Ten         { One             stringstr ="the current array has"+ arr. Count +"Elements: ("; A              for(inti =0; I < arr. Count; i++) -             { -str + =Arr[i]; the                 if(I < arr.) Count-1) -                 { -str + =","; -                 } +             } -str + =")"; + Console.WriteLine (str); A         } at         Static voidMain (string[] args) -         { -             //1. Create an object first -ArrayList arr =NewArrayList (); - Log (arr); -  in             //add elements using the Add () method, no restrictions on element types -Arr. ADD ( -); toArr. ADD (2.5f); +Arr. ADD ("Li"); - Log (arr); the  *             //use [subscript] to get the element at the specified position $             //Console.WriteLine (arr[0]);Panax Notoginseng  -             //gets the number of elements in the current array the             intCount =arr. Count; +  A             //use the Insert () method to insert an element into a subscript position theArr. Insert (1,"Zhao"); + Log (arr); -  $             //remove a specified element from an array using the Remove () method $Arr. Remove ("Zhao"); - Log (arr); -             //Use the RemoveAt () method to delete the element that specifies the location of the subscript theArr. RemoveAt (0); - Log (arr);Wuyi  the             //Use the bool Contains () method to determine whether the specified element exists in the current array -             BOOLb = arr. Contains ("Li"); Wu  -             //empty the entire array About arr. Clear (); $  -         } -     } -}

"Learning Notes" C # ArrayList

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.