Asp tutorial. net class/object/structure/method/function/attribute/array
Namespace arraylist2
{
Class program
{
Static void main (string [] args)
{
// The clear, remove, removeat, and removerange methods of the arraylist are listed below.
Int [] arr = new int [9] {1, 2, 3, 5, 6, 7, 89, 12,120 };
Arraylist list = new arraylist (arr );
Console. writeline ("original arraylist set :");
Foreach (int I in list)
Console. write (I + "");
Console. writeline ();
Console. writeline (list. contains (2); // You can check whether the set contains array 2.
List. remove (5); // delete a set containing 5 values
Foreach (int I in list)
Console. write (I + "");
Console. writeline ();
List. removeat (1); // delete the value at the position where the index is 1
Foreach (int I in list)
Console. write (I + "");
Console. writeline ();
List. removerange (5, 2); // delete two elements from the position where the index is 5
Foreach (int I in list)
Console. write (I + "");
Console. writeline ();
Console. writeline (list. contains (2 ));
List. clear (); // clear all elements in the set
Foreach (int I in list)
Console. write (I + "");
Console. writeline ();
Console. readkey ();
}
}
}
In my understanding, a class is an abstract object set that combines the same features of an object.
A structure is a value type used to encapsulate a group of related variables. It is similar to a class, but has more restrictions and does not support inheritance (class supports single inheritance)
Classes and structures can contain -- attributes and methods (attributes are generally defined by get-set accessors. Methods and functions are the same. Static methods [cannot operate on specific instances] cannot be accessed using this, non-static
One-dimensional array, two-dimensional array (the first matrix can be easily understood)
One-dimensional array length calculation: arr. length two-dimensional: row = arr. rank column = arr. getupperbound (arr. rank-1) + 1
Arraylist, with a powerful number, why do we still need arraylist?
1: arraylist can automatically expand the capacity, and the array is fixed
2: arraylist can add, delete, and insert a range of methods, arrays can only be a single operation
3: arraylist provides a method to return read-only and fixed-size packages to a set. Arrays cannot
Disadvantage: arraylist can only be one-dimensional
My personal feeling: the complementary arraylist and array cannot be replaced. To use arraylist, you need to call the system. collections namespace.