. NET get Set Usage Summary 1th/3 page _ Practical Tips

Source: Internet
Author: User
Tags modifier
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.