There are three types of content in a C + + class: member variables, member functions, and friends.
In general, member variables describe the properties of a class, member functions describe the operation of a class, a friend is a special declaration, a function or class declared as a friend can manipulate its own private member variables and member methods.
In Java, there are two classes of members of a class: properties, which are equivalent to C + + member variables, and methods that are equivalent to C + + member functions.
In C #, there are four members of the class: Fields, Properties, methods, and events (the event has not yet been learned, pause explaining 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0057.gif "alt=" j_ 0057.gif "/>).
A field is equivalent to a member variable in C + + and a property in Java, a variable defined in a class (which can be a primitive type or a reference type), and generally, a field is defined as private.
A method is equivalent to a member function in C + + and a method in Java, which is a function defined within a class.
One of the new things: properties
In Java, Java, because the properties of a class are generally defined as private and cannot be manipulated outside the class, you must provide the appropriate function to set or get the value of the private property. In general, the method that sets the property value begins with set, and the method that gets the value of the property begins with get.
While it is possible to manipulate private fields in C # in the same way, a new feature is provided in C # to achieve this, which is the property.
First, consider the definition of the attribute:
Access modifier Type property name
{
Get
{
Code snippet
}
Set
{
Code snippet
}
}
Formally, the definition of a property is much like the definition of a method, except that it has no parameters.
Looking at the use of properties, the use of properties is much like using a common field.
You can assign a value to a property, or you can use the value of the property directly. For example:
Class myclass{public int MyInt//common property named MyInt {get {//code snippet} set {//Code snippet}}}
In a program, you can use this property
MyClass C = new MyClass (); c.myint = 100; Console.WriteLine (C.myint);
Isn't it much like using a field?
Classes in C #: Fields, Properties, methods