This article reprinted from http://blog.csdn.net/tianyao9hen/article/details/50890827 thanks to original
Property
Setting properties for a class allows you to get information through get and set, so that you can set a private element.
General attributes start with capital letters (EP:NAME)
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacestudy1_repeat{classProgram {Static voidMain (string[] args) {Classtext ct=NewClasstext ("Li Gang"); Console.WriteLine (Ct. Name); Ct. Name="Liu Ming"; Console.WriteLine (Ct. Name); Console.ReadLine (); } } //Add a class classClasstext {//Private Elements PrivateString name; PublicClasstext () {Console.WriteLine ("Ceshi"); } PublicClasstext (String name) { This. Name =name; } //Setting Properties//after you set the properties, you can call the name method PublicString Name {Get{//return element, get property returnname; } Set { //causes the name to get the corresponding element, set the property//Correspondence: Ct. Name = "Liu Ming";Name =value; } } }}Method
Modifier return type method name (parameter list)
{
Method body;
}
If you write a return type, you must return a value that is the same as the return type with return.
If you do not write the return type, you will use void.
Static methods and Instance methods
Using the Static keyword
- Static methods belong to the class itself and do not belong to any object. A static method can only access static members in a class and cannot manipulate specific objects. Therefore, this is not available in static methods. When a static method runs, the object does not necessarily exist.
- Instance methods can use any member of the class. Instance methods can access static and instance members.
Instance variable:
int I
Static variables:
static int I
Example method:
void example () {}
static method:
static void Example () {}
Properties and methods for C # classes