Automatically generate property Get and set methods in VS

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_62ff35cc010190wi.html

Today found a very useful shortcut built, ctrl+r,ctrl+e These two key combinations, you can automatically generate the properties of the get and set methods.
Unlike the Java syntax, there are both field and properity in. NET, in addition to the Get/set method.
field is a private field, used internally, to have a bottom line before the variable name. Properity is a public property that is externally visible, with no line drawn before the variable name.

Of course, you can also use the mouse to select a field variable without a shortcut key, and then right-click Refactor (Refactor) and encapuslate field (encapsulate fields). The effect is as follows: #region field
02Privateint_levelid;
03Privatestring_levelname;
#endregion
05
Properity #region
07 Public intLevelid
08 {
09 Get{ return_levelid; }
10Set{_levelid =value; }
11}
12 PublicstringLevelName
13 {
14 Get{ return_levelname; }
15Set{_levelname =value; }
16}
#endregion

The better thing is to just type in the prop and then press TAB twice. The get/set is automatically generated. You only need to modify the property name.

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.