C # development can run in. for applications on the net platform, C # itself is only a language, although it is used to generate oriented. net Environment Code, but it is not. net
Console. writeline
Namespace -- using command imports the type members in the namespace identified by the namespace name into the current compilation unit, so that they can be directly used (without the need to add a fully qualified name)
An organizational form of a program-internal or external (an organizational structure made public to the outside)
You can define a namespace in the project namespace, but you cannot use using to reference a custom namespace.
All statements of C # Must be in the class.
The main method is the entry point of the program. a c # program can only have one main method, which must be static.
The value type is inherited from the system. valuetype class-Stack
Reference Type -- memory must be allocated for reference type variables in the managed heap, which is managed and controlled by the garbage collector. -- heap
Each value type has an implicit default constructor to initialize the default int I = new int () of this type. It is equivalent to int32 I = new int32 ();
All value types of C # are implicitly derived from system. valuetype, while system. valuetype is directly derived from system. object -- system. valuetype is a class type rather than a value type. The key is that valuetype overrides the equals method to compare the value type by instance value instead of the reference address.
Int ls = 927; // declare an int type variable ls byte shj = 255; // declare a byte type variable shj console. writeline ("ls = {0}", ls); // output the int type variable ls console. writeline ("shj = {0}", shj); // output the byte type variable shj
Use Enum in C # To declare the enumeration type
Type conversion
Implicit
Explicit
Packing and unpacking (Packing -- implicitly convert the value type to the reference type, and unpacking -- allow converting the display of the reference type to the value type)
Int I = 2008; // declare an int type variable I and initialize it to 2008 object OBJ = I; // declare an object type OBJ, whose initial value is I console. writeline ("1. The value of I is {0}, and the boxed object is {1}", I, OBJ); I = 927; // assign an I value to the 927 console. writeline ("2. The value of I is {0}, and the boxed object is {1}", I, OBJ); console. readline ();
Changing the value of the value type variable after packing does not affect the value of the boxed object.
Int I = 112; // declare an int type variable I and initialize it to 112 object OBJ = I; // perform the packing operation console. writeline ("packing operation: the value is {0}. After packing, the object is {1}", I, OBJ); Int J = (INT) OBJ; // execute the unpacking operation console. writeline ("binning operation: boxed object: {0}, value: {1}", OBJ, J); console. readline ();
The types before and after unpacking must be consistent; otherwise, an exception may occur.
A constant is modified with const, and its initial value must be set when a constant is created.
Special operators in C #
Is checks whether the variable is of the specified type. The is operator cannot be overloaded.
Typeof is used to obtain the type of the system prototype object, that is, the type object. The type class contains information about the value type and reference type.
Type mytype = typeof (INT );
Char represents a Unicode Character in C #
Incontrol
Isdigit
Isletter
Isletterordigit
Islower
Isnumber
Ispunctuation punctuation category
Isseparator separator category
Isupper
Iswhitespace
Parse converts the value of the specified string to its equivalent Unicode Character
Tolower
Toupper
String, which is the alias of the string class
The value of the string object cannot be changed. The variable defined by the string class is a reference type.
Comparison string
Compare (bool ignorecase)
Compareto -- compare the instance object with the specified string
Equals -- whether the two strings are the same (case sensitive and regional)
Format a string
Format -- index placeholder (format item)
String stra = "download you for a lifetime"; // declare the string stra string strb = "Never give up"; // declare the string strb string newstr = string. format ("{0}, {1 }!!! ", Stra, strb); // format the string
Date Format Specification
Datetime dt = datetime. Now; // obtain the current system date string strb = string. Format ("{0: d}", DT); // format it into the short Date Format
Truncate string
Substring
Split string
Split
String stra = "use ^ lifetime # download, you"; // declare the string stra char [] separator = {'^ ','#',','}; // declare the string [] splitstrings = new string [100]; // declare a string array splitstrings = stra. split (separator); // split the string
Insert and fill strings
Insert padleft padright
Delete string
Remove
Copy string
Copy copyto -- copy a part of the string to another Array
String str1 = "download you for a lifetime"; // declare a string variable str1 and initialize char [] STR = new char [100]; // declare a character array STR // copy the four strings starting from Index 1 to str1.copyto (1, STR, 0, 4) in the character array STR );
Replace string
Replace
Variable string stringbuilder
In the system. Text namespace, the string object cannot be changed. Every time you use methods in the string class, you must create a new String object in the memory. If you need to modify the string repeatedly -- stringbuilder
Stringbuilder ls = new stringbuilder ("download you in a lifetime", 100); LS. append ("vs yunye xiangfeng"); // append the string to the console at the end of the LS using the append method. writeline (LS); // output ls // use the appendformat method to append the string to the end of ls in the specified format. appendformat ("{0: c}", num); console. writeline (LS); // output ls. insert (0, "Name:"); // use the insert method to append "name:" To the console at the beginning of LS. writeline (LS); // output ls // use the Remove Method to delete the string ls after the index 15. remove (15, ls. length-15); console. writeline (LS); // output ls // use the replace method to replace "name:" with "life-loving" ls. replace ("name", "love for life ");