[英]How can I auto generate standard code for getters and setters and constructors in Visual Studio?
I created a class in C# with Visual Studio containing a bunch of variables. 我在C#中用Visual Studio创建了一个包含一堆变量的类。 How can I auto-generate Constructors, getters and setters for them?
如何为它们自动生成构造函数,getter和setter? I know such features from other programming software for developing in Java like Android Studio and Eclipse and I don't find this feature in Visual Studio.
我知道其他编程软件的这些功能,用于开发Java,如Android Studio和Eclipse,我在Visual Studio中找不到这个功能。
This: 这个:
public string TestString { get; set; }
Is equivalent to this: 相当于:
private string _testString;
public string TestString
{
get
{
return _testString;
}
set
{
_testString = value;
}
}
If you are using Visual Studio, you can use code snippets to generate boilerplate code for you. 如果您使用的是Visual Studio,则可以使用代码段为您生成样板代码。
Type ctor
and press Tab . 键入
ctor
并按Tab键 。 It will generate a parameterless constructor for the class you are currently in. 它将为您当前所在的类生成无参数构造函数。
Type prop
and press Tab . 键入
prop
并按Tab键 。 Then type the datatype you want your property to be and press Tab twice. 然后键入您希望属性的数据类型,并按两次Tab键 。 Finally, type the name of the property and press Tab one last time.
最后,键入属性的名称,最后按Tab键一次。 It will generate an auto implemented property for you.
它将为您生成一个自动实现的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.