Set in C # (Array/ArrayList/List & lt; T & gt;/HashTable/Dictionary ),

Source: Internet
Author: User

Set in C # (Array/ArrayList/List <T>/HashTable/Dictionary ),

Int [] numbers = new int [5]; // The length is 5 and the element type is int.
String [,] names = new string [5, 4]; // a two-dimensional array of 5*4
Byte [] [] scores = new byte [5] []; // an array with a length of 5. The element is a byte array, and the length of the element array is unknown.

Different formats:
Int [] numbers = new int [5];
Int [] numbers2 = new [] {100,200,300,400,500 };
Int [] numbers3 ={ 100,200,300,400,500 };

 

System. Collections. ArrayList

ArrayList al = new ArrayList ();

Al. Add (5 );

Al. Add ("Hello Tom ");

System. Collections. Generic. List <T>

List <int> intList = new List <int> ();

IntList. Add (1, 500 );

IntList. AddRange (new int [] {1,100 };

IntList. Insert (1, 1000 );

Cw (intList. Contains (100 ));

Cw (intList. indexOf (10 ));

System. Collections. HashTable

HashTable ht = new HashTable ();

Ht. Add ("name", "Tom ");

Ht. Add ("age", 18 );

System. Collections. Generic. Dictionary

Dictionary <string, string> dic = new Dictionary <string, string> ();

Dic. Add ("name", "Tom ");

Dic. Add ("age", "eighteen ");

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.