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 #