References, fields, properties, constructors in C #

Source: Internet
Author: User

One , the difference between the reference assignment and the ordinary assignment value

Pointers are not completely discarded in C #, pointers are called references in C #, they are similar but not exactly, and their use of pointers is as follows:

(same color note contrast)

In the C language:

INTR*P1,*P2;

int a=10,b=20;

p1=&a;

p2=&b;

P2=P1;

-------------------------------------------------------------------------------------------------

In C #:

Class Person

{

int age;

String name;

}

Person p1,p2;//(similar to CHAR*P1,*P2;) After this expression executes, the system simply allocates two addresses to hold the two class variable names, and does not allocate space of length int+string size

p1= new Person ();

p1.age= Ten; After this two-type execution the system allocates memory to store p1.age and P1.name values, while P1 points to this memory space

p1.name= "WWE";//(at this point the equivalent of int a=10,b=20;p1=&a;p2=&b;)

p2= p1;//p2 and P1 point to the same memory space (corresponding to P2=P1 in C)

-----------------------------------------------------------------------------------------------

Ii. fields, Attributes

Class Person

{

int age;//field (just a normal variable)

int age//Property (essentially a function that is used to manipulate fields)

{

Get{return age;}

set { age=value;}

}

Third, the constructor function

Class Person

{

int age;//field (just a normal variable)

Public person ()//essence is a function, but there is no return value , the name is the class name , used to initialize the object, that is, to do the assignment of the field, pay attention to the comparison with the attributes of their similarities and differences

{

age=10;

}

References, fields, properties, constructors in C #

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.