C # Supplements's trivia (vi): arrays

Source: Internet
Author: User
Array:

Int [] intarray = new Int[6];int [] intarray = new Int[2][];int [][][] intarray = new Int[2][][];intarray[1][2][1] = 3;I NT [,] myTable = new int[2,3];mytable[1,3] = 3;

The Length property contains the number of elements in each dimension of the array.

The GetLength () method gives the number of elements in one dimension of an array.

The GetUpperBound () method gives an index of one dimension of an array to go live.

The GetUpperBound () method gives the index of a certain dimension of an array.

ArrayList:

A collection similar to an array that can dynamically change the number of elements in a collection.

public class array    {    ArrayList AL = new ArrayList ();    public void Add ()    {        AL. ADD ("LSDKJF");        AL. ADD (8);    }    }

Count gets the number of elements in the collection.

Adds an element at the end of Add (object).

Remove (object) removes an element.

RemoveAt (int) Removes the elements of the specified index from the collection.

Insert (int,object) adds an element at the specified index.

Clear () removes all elements.

Contains (Object) Returns a Boolean type that indicates whether the specified element is included.

The elements in the CopyTo () collection are copied to the specified collection, and you can specify which element to start with.

IndexOf (object) Returns the position of the first occurrence of the specified element if no return-1 is present.

LastIndexOf (object) Returns the position of the specified element most once, if no return-1 is present.

ToArray () returns an array of type object that contains all the elements in the ArrayList collection.

TrimToSize () Sets the value of the capacity property to the actual number of elements in the current ArrayList collection.

Stack collection Processing stacks

Stack (Stack collection) follows the LIFO principle. (Press in from top down)

  Stack s = new stack ();    S.push (2);

Push (object) into the stack operation.

The number of elements in the count stack.

Pop () removes and returns the element at the top of the stack. (which is the most pressing element, at the top)

Peek () Returns the object at the top of the stack without removing it. (with pop, output the last pressed element, at the top)

Queue Collection processing queues:

The Queue (Heap collection) is based on the FIFO principle.

Queue q = new Queue ();

Q.enqueue (3);

Enqueue (object) Adds an object to the end of the queue.

Dequeue () Removes and returns the object at the top of the queue.

Peek () Returns the object at the top of the queue, but does not remove the object.

The number of elements in the Count heap.

HashTable:

The Hashtable collection is stored in the form of a key-value pair.

  HashTable ht = new HashTable ();    Ht. Add ("n", "HHHT");

Hashtable the element, use the index "[]".

Such as:

Object obj = ht["01"]

Add (Object,object) to the Hashtable collection. (Key,value)

Remove (object) Removes the object of the specified key.

SortedList class:

The elements in the SortedList collection are sorted according to their corresponding key values and can be indexed using integer values for the elements in the collection.

SortedList SL = new SortedList ();    Sl. ADD (1, "hhht");

Method properties are similar to Hashtable.

The above is the C # supplements of the Small Knowledge (vi): The contents of the array, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.