In C # arrays, Arraylist,list can store a set of objects.
One, array
Declaration: Data type [] arrayname = new data type [int length];| | data type [] arrayname = new data type []{AA,BB,CC,DD};
Assignment: obj = arrayname[index];arrayname[index] = obj;
Feature: It is continuously stored in memory, so its index speed is very fast, and the assignment and modification elements are simple. The length must be specified .
Application scenario: Used in clear array length and fixed length.
Second, ArrayList
Statement: ArrayList arraylist= new ArrayList ();
Action: Arraylist.add (obj);//Add Object Arraylist.removeat (index),//Remove Object ArrayList. Insert (index, obj);//Insertion Object arraylist[index] = obj;//Assignment | | Modify Value obj = Arraylist[index];//value
Attribute: ArrayList is part of the namespace System.Collections and must be referenced when using the class, inheriting the IList interface, providing data storage and retrieval. The size of the ArrayList object is dynamically expanded and shrunk according to the data stored in it. Therefore, you do not need to specify the length of the ArrayList object when declaring it .
Scenario: Because ArrayList objects within an array do not have a type requirement, there may be objects within the arrays that are not of the same type, that is, ArrayList is not type-safe. Boxing and unboxing operations typically occur when a value type is stored or retrieved, resulting in significant performance wear and tear. So we don't know the length of the array and whether the object data types in the array are uniform.
Third, generic list
Declaration:list<t> arraylist= new list<t> ();
Action: Arraylist.add (obj);//Add Object Arraylist.removeat (index);//Remove Object Arraylist.insert (index, obj);//Insert Object Arraylist[index] = obj; Assign Value | | Modify Value obj = Arraylist[index];//value
Attribute: The list class is a generic equivalent class of the ArrayList class, and most of its usage is similar to ArrayList because the list class inherits the IList interface. The key difference is that when declaring a list collection, we also need to declare the object type for the data in the list collection.
Scenario: We use the array length and the consistency of the object data types within the array.
Write in the following: the capacity of the array is fixed, and the capacity of the ArrayList and list can be modified as required. The list is more cost-efficient than ArrayList when using a value type to make a boxed unboxing operation.
C # arrays, ArrayList, and lists