This keyword refers to the current object itself, and generally refers to the object itself
In a class, the constructor usually calls one party with fewer parameters.
The following is an example:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace ooptext
{
Public class person
{
/// <Summary>
/// Field
/// </Summary>
Private int ID;
Public int ID
{
Get {return ID ;}
Set {id = value ;}
}
Private string name;
Public string name
{
Get {return name ;}
Set {name = value ;}
}
Private string password;
Public String Password
{
Get {return password ;}
Set {Password = value ;}
}
/////////// If two parameters are sent, I also call the constructor of the three parameters in disguise, but I write the third parameter as a constant.
Public Person (int id, string name)
: This (ID, name, "456789 ")
{
}
/////////// When three parameters are sent, directly drop the constructor with three parameters. This refers to the object itself that is currently instantiated.
Public Person (int id, string name, string password)
{
This. ID = ID;
This. Name = Name;
This. Password = password;
}
Public void say ()
{
Console. writeline ("Hello {0} My name is {1}, my password is {2}", ID, name, password );
}
Static void main ()
{
Person = new person (1, "Xiaogang ");
Person. Say ();
}
}