One of the highlights in this essay is that the keywords provided in C # are simplified symbols for the corresponding system type (such as int is a simplified symbol of the System.Int32 type)
I. Built-in data types and hierarchies
All C # built-in data types support default constructors, in short, this feature allows us to create variables using the new keyword, which automatically sets the variable to its default value.
1, the bool type is set to false;
2, the value type is set to 0;
3, char type is set to a single null character;
4, float set to 0.0;
5, the BigInteger variable is set to 0;
6, the datetime type is set to 1/1/0001 12:00:00 AM;
7, the object reference (including string) is set to null;
The following is the code that uses new to create a basic data type variable, although it is cumbersome, but the code is actually feasible:
Console.WriteLine ("Using New to create variables:"); BOOLb =New BOOL(); inti =New int(); DoubleD =New Double(); DateTime DT=NewDateTime (); floatf =New float(); Console.WriteLine ("{0},{1},{2},{3},{4}", b, I, D, DT, f);//output: FALSE,0,0,0001/1/1 0:00:00,0
II. hierarchical structure of data types
In C #, each base data type has a class hierarchy, and types at the top of the class hierarchy provide some default behavior for derived classes. The relationship between the core system types is as follows:
All of the above types derive from System.Object, which defines a set. NET base Class library, such as ToString (), Equals (), GetHashCode (), and so on, a simple code to understand some of these underlying methods:
Console.WriteLine ("12.gethashcode={0}", A. GetHashCode ());//12.gethashcode=12Console.WriteLine ("12.Equals (+) is {0}", A. Equals ( at));//12.Equals (%) is FalseConsole.WriteLine ("12.ToString () is {0}", A. ToString ());//12.ToString () isConsole.WriteLine ("12.GetType () is {0}", A. GetType ());//12.GetType () is System.Int32
Third, the member of the numeric data type
1.. NET numeric types support the MaxValue and MinValue properties, which illustrate the range that a given type can store;
Console.WriteLine ("Max of int is {0}",int. MaxValue);//output: Max of int is 2147483647Console.WriteLine ("Min of int is {0}",int. MinValue);//output: Min of int is-2147483648Console.WriteLine ("Max of Double is {0}",Double. MaxValue);//output: Max of Double is 1.79769313486232E+308Console.WriteLine ("Min of Double is {0}",Double. MinValue);//output: Min of double is-1.79769313486232e+308
In addition to the MaxValue and MinValue properties, a given system data type may also define other more useful members, for example, you can get positive infinity and infinite decimals with the System.Double type:
Console.WriteLine ("Min of double is {0}"double.) PositiveInfinity);//output: Positive Infinity large Console.WriteLine ("Min of double is {0}"double . negativeinfinity);//output: infinitesimals
Console.WriteLine ("Min of Double is {0}", double. Epsilon);//output: Minimum positive system.double value greater than 0 4.94065645841247E-324
Iv. members of the System.Boolean
1. TrueString This property returns True
2. FalseString This property returns false
Console.WriteLine ("bool. TrueString is {0}"bool. truestring); // output: bool. TrueString is TrueConsole.WriteLine ("bool. FalseString is {0}"bool. falsestring); // output: bool. FalseString is False
V. Members of the System.Char
Text data in C # is represented by the string and char keywords, which are simplified symbols for System.String and System.Char, string for a contiguous set of words such as "Hello", and char to represent a single word such as ' a ', System.Char In addition to representing a single character, but also retains a lot of functionality, using the static method of System.Char, you can determine whether a character is a number, letter, punctuation, or other;
CharMyChar ='a'; Console.WriteLine ("Char. IsDigit (' a '): {0}",Char. IsDigit (MyChar));//output: Char. IsDigit (' a '): False to determine whether the specified Unicode character belongs to the decimal number category. Console.WriteLine ("Char. Isletter (' a '): {0}",Char. Isletter (MyChar));//output: Char. Isletter (' a '): True to determine whether the specified Unicode character belongs to the Unicode letter category. Console.WriteLine ("Char. Iswhitespace ("): {0}",Char. Iswhitespace (' '));//output: Char. Iswhitespace ("): True---Determine if the target character is not a null characterConsole.WriteLine ("Char. Iswhitespace (' Hello World ', 5): {0}",Char. Iswhitespace ("Hello World",5));//output: Char. Iswhitespace (' Hello World ', 5): True---Determine if the fifth character in the "Hello World" string is not a spaceConsole.WriteLine ("Char. Iswhitespace (' Hello World ', 6): {0}",Char. Iswhitespace ("Hello World",6));//output: Char. Iswhitespace (' Hello World ', 5): False---Determine if the sixth character in the "Hello World" string is not a spaceConsole.WriteLine ("Char. Ispunctuation ('? '): {0}",Char. Ispunctuation ('?'));//output: Char. Ispunctuation ('? '): True---Judge '? ' is not a punctuation category
Get string values from string data and parse to C # system values
. NET data type provides the ability to generate the corresponding underlying type of variable by the given text (string). This technique converts the data entered by the user into a numeric value. ---in short, data type conversions from string to numeric
Console.WriteLine ("Data Type parsing:");BOOLb =BOOL. Parse ("true"); Console.WriteLine ("Value of B is {0}", b);//output: Value of B is TrueDoubleD =Double. Parse ("666.666"); Console.WriteLine ("Value of D is {0}", d);//output: Value of D is 666.666inti =int. Parse ("666"); Console.WriteLine ("Value of I is {0}", i);//output: Value of I is 666Charc =Char. Parse ("C"); Console.WriteLine ("Value of C is {0}", c);//output: Value of C is C
VII, System.DateTime and System.TimeSpan
A number of useful data types are defined in the System namespace, and there are no C # keywords for these data types, such as datetime and TimeSpan structures
Console.WriteLine ("DateTime and TimeSpan");D atetime DT=NewDateTime (1994,9, -); Console.WriteLine ("The day of {0} is {1}"Dt. Date, dt. DayOfWeek);//output: the day of 1994/9/18 0:00:00 is SundayDT = dt. AddMonths (2); Console.WriteLine ("Daylight savings:{0}"Dt. IsDaylightSavingTime ());//output: Daylight savings:false---Determine if the current month is summerTimeSpan TS=NewTimeSpan (6,6,6); Console.WriteLine (TS);//Output: 06:06:06Console.WriteLine (TS. Subtract (NewTimeSpan (0,2,0)));//Output: 06:04:06
C # Core built-in data types