C # more variable content

Source: Internet
Author: User

I. type conversion

1. Implicit conversions 2. Explicit conversions 2. Enumeration 1. Defining Enum typename: underlyingType {Value1, Value2, Value3 ,....} The basic enumeration types include bytes, sbyte, short, ushort, int, uint, long, And ulong:
Namespace Ch05Ex02

{

// Define Enumeration

Enum oritentation: byte

{

North = 1,

South = 2,

East = 3,

West = 4,

}

 

Class Program

{

Static void Main (string [] args)

{

Byte diByte;

String diString;

DiByte = (byte) oritentation. north; // display conversion. Even if the basic oritentation type is byte, (byte) data type conversion is still required.

DiString = Convert. ToString (oritentation. north); // you can use the ToString () command to obtain the enumerated string value.

Console. WriteLine ("Byte = {0}", diByte );

Console. WriteLine ("String = {0}", diString );

Console. ReadKey ();

}

}

}
3. The structure is a data structure composed of several data types. Define the structure Struct <typename >{< access modifier> <basic type> <name >}iv. array declaration array <basetype> [] <name> <basetype> Any Type the array must be initialized before access, initialization can be divided into two types: Specify the array content literally, or specify the array size, for example: int [] myIntArray = {5, 9,}; 2, use the keyword new to initialize all array elements. Example: int [] myIntArray = new int [5]; multi-dimensional array <basetype> [,] <name> // define a two-dimensional array multi-dimensional array with more commas, for example, <basetype> [,] <name> // declares a 4-dimensional array. 5. string processing <string>. toLower () converts string to uppercase <string>. toUpper () converts a string to lowercase <string>. trim () deletes spaces in the input string <string>. trimStart () deletes the space before the string <string>. trimEnd () removes spaces after a string <string>. padLeft () adds a space on the left of the string <string>. padRight () adds a space to the right of the string <string>. split () converts a string to a string array <string>. replace (string oldValue, string newValue) replaces string with another specified string
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.