1. 6. Unified system Type)
C # A unique type-a unified system type (I have a headache for this death. Make sure you have a better name.
Me ). In short, all other types, including values and references, can be treated as a unified system type. Conceptually,
All types are derived from it. In this way, attributes and methods of the unified system type can be used for other types. Including some
Single "type, such as: int. Let's give an example :*/
Using System;
Class Test
{
Static void Main (){
Console. WriteLine (3. ToString ());
}
}
/* "3. ToString ()" calls the "ToString ()" method of the object. I believe that all the friends who have learned c/c ++ know that they want to output
It's time to worry about numbers. Another one :*/
Class Test
{
Static void Main (){
Int I = 123;
Object o = I; // boxing
Int j = (int) o; // unboxing
}
}
/* In this example like a hat trick, convert from "int" to "object" and then back. In this way
A bridge is built between them. How can this be used. An impromptu example is like min. In c/c ++ :*/
// C/c ++ code
Void min (int I, int j)
{
Return (I <j )? I: j );
}
/* What if the comparison is not int, or maybe int, float, or double? You can do this :*/
Template <class T>
T min (T I, T j)
{
Return (I <j )? I: j)
}
/* Use c :*/
Void swap (object a, object B)
{
Return (I <j )? I: j );
}
/* I think you must see that if the second example compares an int and a float, some conversions are required, while the third one is
In this example, we can compare all the variables! This flexibility is too great. Therefore, I personally think that everyone must be careful when using it!
It will never report an error when comparing an int with a class. Haha, I found that my translation is always getting farther and farther, always
Cannot hold the original text. You have been tampered with a lot. Please forgive me!