During the early learning of C #, you often encounter such statements:
public string Studentname
{
Get{return Stuname;}
Set{stuname=value;}
}
I didn't quite understand why I was doing this. After learning the C #, I can't make a summary of it. Today I saw the book "Visual c#.net Program Design Course", summed up well, take notes:
In many object-oriented programming languages, attributes (property) refers to the object's characteristics and state, specifically refers to the object's data members. Programmers can specify whether a data member can be accessed directly by the outside world, and if the data member is specified as public, the member can be accessed by the "object name. Common data member name". C # is a fully object-oriented language, and C # advocates a new way to better encapsulate and protect data members while providing more efficient forms of access to the outside world. C # is used to achieve this goal is "properties", and those data members, in C # is called "Field" or "field."
Definition and use of attributes
A property consists of two parts: the property header and the memory. The memory is divided into a get accessor and a set accessor. The general form of declaring properties is:
Modifier Type property Name
{
Get//get Access Program
{...}
Set//set Access Program
{...}
}
The modifier of a property can be any access control character, and can also be defined as static. Get and set are a specific way in which a fetch is used to read data from an object, and set is used to write data to a field, and when the data is written to fields, C # uses value to represent the input data, and value is a quasi-keyword, for example:
Set{afield=value;}
Current 1/3 page
123 Next read the full text