Automatically generate property Get and set methods in VS

Source: Internet
Author: User
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 .
And the Java syntax is different, in addition to the Get/set method of writing, there are. net in both field and properity.
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 Encapuslatefield (encapsulate the field). The effect is as follows:

#region field
 private int _levelid;
 private string _levelname;
#endregion

#region properity public
 int levelid
 {get
     {return _levelid;}
     set {_levelid = value;}
 }
 public string LevelName
 {get
     {return _levelname;}
     set {_levelname = value;}
 }
#endregion



The better thing is to just type in the prop and then press TAB twice. The Get and set are 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.