C#. NET Frequently asked Questions (FAQ) What is the meaning of the-get set property

Source: Internet
Author: User

Using Get,set can make the class definition more canonical, because, normally, if we write a custom class, his property is either public or private, but if the properties of public are to be restricted, such as a person's age does not allow negative numbers, nor is it allowed to be greater than 150, Then you are only limited to the int type is not enough. A person's name does not allow less than two characters and does not allow more than 5 characters, then you are only limited to string is not enough. So the essence is Get,set is the interface to define read and write variables (the most common is the user registration when the user name, mailbox, mobile phone number, etc. will be limited)

?

As shown, the original public property is set to private, but need to let the outside read and write, so do get and set two methods, which is the most common understanding

?

But the above method is our own implementation, the more standard is put together, C # provides such a template, whether read or write will not be null, empty this result, essentially with the previous write two methods read and write is the same

?

?

For more instructional videos and downloads, please pay attention to the following information:

My Youku Space:

Http://i.youku.com/acetaohai123

?

My online forum:

http://csrobot.gz01.bdysite.com/

?

Problem Exchange:

qq:910358960

Email:[email protected]

?

?

C#. NET Frequently asked Questions (FAQ) What is the meaning of the-get set property

Related Article

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.