Beginner with c # 6

zhaozj2021-02-08  282

Drive out a series! Please correct!

1.6 Unified System Unce (Type System Unification)

C # created a type - unified system type (for this self-prison, my headache is dead. Who has a better name, please tell

I). In summary, all other types, including values, and references can be treated as a unified system type. In concept,

All types are derived from it. In this way, other types of the type of system can be used. Including some "simple

"Type", such as: int. Or give an example: * /

Using system;

Class test

{

Static void main () {

Console.writeline (3.toString ());

}

}

/ * "3. Tostring ()" calls the "toString ()" method of Object. I believe that friends who have learned C / C know that they want to output one.

How much is the number, and now it is. Look at one: * /

Class test

{

Static void main () {

INT i = 123;

Object o = i; // boxing

INT j = (int) o; // unboxing

}

}

/ * In an example of a hat trick, switch from "int" into "Object" and conversion. In this way, at the value and reference

There is a bridge between it. What is the use of this? Improve a common example ... Just MIN. In C / C : * /

// c / c code

Void Min (int I, int J)

{

RETURN ((i

}

/ * If it is not int, or maybe Int, maybe Float, Double? It can be like this: * /

Template

T min (t i, t j)

{

Return ((i

}

/ * With C # can: * /

Void Swap (Object A, Object B)

{

RETURN ((i

}

/ * I think everyone must see the second example to compare an int and a float, there is also some conversion, and the third

Examples can compare all variables! This flexibility is too big. Therefore, I have thought that everyone must be careful when using it!

It will never report an error while comparing an int and a class. Oh, I found that my translation always runs more far, always

Can not hosted the original text. Tamper, please forgive!

转载请注明原文地址:https://www.9cbs.com/read-2825.html

New Post(0)