Beginner with c # 3

zhaozj2021-02-08  216

I am very busy recently, I have written this. Forgive me! Mr. Wang should not be the first one! Haha

1.3 type

C # supports two basic types: one is value types, one is reference (Reference Types). Value includes simple types

(CHAR, INT, and FLOAT), enumeration (ENUM) and Structures. Quote includes classes, interfaces (Interface),

Delegate and array arrays (Array). The value is different from the reference: the value directly stores its data content; and reference storage objects

Quote. Is it a powder? ! Have a bit more. You bought a chamber (good) in a certain place. But I have never been to, I only know the address, how

Do you do it? You can take a taxi, the driver knows how to don't worry about you. The address in your hand is like the name of the object, you

It is written in the program, it seems to give the address to the driver. The driver is your compiler, it knows where to go. Your luxury house is like that

NGWS SDK development package (82MB, luxurious! 俺 Mh - just burn this). There is a stuff in the house, such as you want to write a sentence.

(I DONT LIKE HELLO World), it seems that the above example is to use "WriteLine". So, you give "WriteLine"

The address, such as "console.writeline". understand? ! I can be tired. Zzz ... (strong spirit) I don't know if you think,

The difference between values ​​and references can lead an important feature. Value variables and variable stored data is one or one, uniqueness. And the reference is not

Hereaway. Different variables in the reference can reference the same object. Other references this instance when one of the variables change the value of the instance

Variables will also be affected (of course, the variables itself has not changed, ie, the address is not changed). Hey, the variable is only the location of the storage object (ground

Site), not the object itself. It is like your beautiful house being burned, but your address has not changed, but the address corresponding to the address is gone.

Maybe someone else has this address, he went to burn your house! Ok, giving an example: * /

1: USING System;

2: Class Cvalue

3: {

4: public int value = 0;

5:}

6: Class Test

7: {

8: static void main () {

9: int Val1 = 0;

10: INT VAL2 = VAL1;

11: VAL2 = 123;

12: CVALUE REF1 = New CVALUE ();

13: CVALUE REF2 = REF1;

14: Ref2.value = 123;

15: console.writeline ("VALUES: {0}, {1}", VAL1, VAL2);

16: Console.writeline ("REFS: {0}, {1}", ref1.value, ref2.value;

17:}

18:}

/ * The following is the result of the output: Values: 0, 123

REFS: 123, 123

Ah, it should be clear. Variable VAL1 and variable VAL2 does not affect each other, and they have their own storage space. Ref2 replication

REF1, so they reference examples of the same object. When you change one of them, it will affect the other.

value.

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

New Post(0)