Beginner with C # 3

Source: Internet
Author: User
1. 3 types
C # supports two basic types: one is values (value types) and one is reference (reference types). Values include simple types
(char, int, and float), enumerations (enum), and structs (struct). References include classes (class), interfaces (interface),
Represents (delegate) and Arrays (array). A value differs from a reference in that a value directly stores its data content, whereas a reference to a stored object
The reference. is not the powder puzzling?! Let's make an analogy. You bought a villa somewhere (great). But I've never been there, only know the address, how
What do you do? You can take a taxi, the driver read the address and know how to go without you worry. The address in your hand is like the name of the object, you put
It's written in the program, it's like giving the address to the driver. The driver is your compiler, and it knows where to go. Your luxurious house is like that.
NGWS SDK Development Kit (82MB Oh, that's luxurious!) My m ah-so burn it. There are things you want in the house, like you want to write a sentence
Words (I dont like Hello world), as the above example, to use "WriteLine". So, you give "WriteLine."
Address, such as: "Console.WriteLine". Got it?! I can be tired. Zzz ... (Strong spirit) I don't know if you think about it,
The difference between values and references leads to an important feature. The values of variables and variables stored in the data are one by one corresponding, uniqueness. And the reference is not
and Different variables in a reference can reference instances of the same object. When one of the variables changes the value of the instance, other references to the instance
Variables are also affected (of course, the variable itself does not change, that is, the address has not changed). See, the variable simply shows where the object is stored (
Address), not the object itself. It's like your beautiful house has been burned, but your address has not changed, but the address of the corresponding house is gone.
Maybe someone else has this address, he went to burn your house! OK, give me 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:}

/* Below is the result of the output:
values:0, 123
Refs:123, 123

Aha, it should be a clear powder. Variable val1 and variable val2 do not affect each other, they each have their own storage space. and REF2 replication
Ref1, so they refer to an instance of the same object. When you change one of them, it affects the other.
Value.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.