November 3, 2017 VS three broad classes & Arrays &VS& collections & Generic Collections

Source: Internet
Author: User

Three major categories

It is divided into two major categories:

Basic data type & reference type

Basic data type---value type---integral type---commonly used integers: Int, long integer: Long, small integer: Byle, medium integer short

--floating point--small floating point: float, medium floating point: Double large floating point: Declaml

--Boolean--bool (wrong type)--ture| | False

--Character Type-char (single character)

Reference types--strings--string

--Time Date--DateTime

Array

Type must be specified and length must be specified

Int[] A = new int[Tim length];

Int[] B = new int[]{add number};

String[] D = new string[]{"Double quotes with numbers, separated by commas, and a double quote can only be counted as one"};

Of course, not only the int type can be, other can also

Array traversal

Console.WriteLine (add index value inside b[]);

Console.read ();

foreach (int c in b) {

Console.WriteLine (c);

Array sorting

}

Array Assignment

a[index value] = number (because it is of type int);

Two-dimensional arrays

int[,] e = new int[1,1];

int[,] e1 = new int[,]{{},{},{}};

Two-dimensional array values

Console.WriteLine (e1[0,2])//Take two values from the 0th one

Bubble sort

 int[] A =New int[] {9,5,8,4,2,1 };  for(inti =0; I < a.length-1; i++)            {                 for(intIB = i +1; IB < A.length; ib++)                {                    if(A[i] >A[ib]) {                        inth =A[i]; A[i]=A[ib]; A[IB]=h; }                }            }            foreach(intKincha) {Console.WriteLine (k); } console.read ();

Collection

No need to specify type and length

Outside to add: using System.Collections;

ArrayList arr =NewArrayList (); DateTime DT=NewDateTime ( ., One,3);
Add arr. ADD ("ABC"); Arr. ADD (123); Arr. ADD (true); Arr. ADD (DT); //Collection Traversal//foreach (var x in arr)//{ //Console.WriteLine (x); //} //arr. Remove (123); //arr. RemoveAt (1); //arr. Reverse ();//Sequential RolloverArr. Insert (2,"AC"); Console.WriteLine (arr. Contains (123)); //foreach (var x in arr)//{ //Console.WriteLine (x); //}Console.read ();

Generic collection

Not specified length specified type

//class to be on the same lateral as the static void Main (string[] args)classuser{PUBILCintuser_id; PUBILCstringuser_name;}
New Linst<user> i =NewLinst<user>();
Insert User SJ=Newuser (); sj.user_id=1; Sj.user_name="Zhang San"; I.add (SJ); user LS=Newuser (); ls.user_id=2; Ls.user_name="John Doe"; I.add (LS);foreach(User Xinchi) {Console.WriteLine (x.user_id);}

list< type or class table name > i = new list< type or class's Table name > ();

Add to

I.add (e.g. 123);

Regular expressions

 stringstr ="\""; stringtemp =Console.ReadLine (); Regex Rx=NewRegex ("\\d"); if(Rx. IsMatch (temp)) {Console.WriteLine ("non-negative integers"); }Else{Console.WriteLine ("is not"); }

Array

            Try             {                intint. Parse (temp);                Console.WriteLine (" is number ");            }             Catch             {                Console.WriteLine (" you are not entering a number ");            }            Console.WriteLine (x);

November 3, 2017 VS three broad classes & Arrays &VS& collections & Generic Collections

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.