我见过一些人用c#快速创建属性,但他们是如何做到的呢?
在Visual Studio(目前使用Visual Studio 2010)中有哪些快捷方式可以创建属性?
我用的是c#。
例如,
public string myString {get;set;}
我见过一些人用c#快速创建属性,但他们是如何做到的呢?
在Visual Studio(目前使用Visual Studio 2010)中有哪些快捷方式可以创建属性?
我用的是c#。
例如,
public string myString {get;set;}
当前回答
当你在Visual Studio中写作时,
public ServiceTypesEnum Type { get; set; }
public string TypeString { get { return this.Type.ToString();}}
ReSharper会继续建议将其转换为:
public string TypeString => Type.ToString();
其他回答
在c#中:
private string studentName;
在行末分号(;)之后只要按
Ctrl + R + E
它会显示一个弹出窗口,像这样: 点击Apply或按ENTER,它将生成以下属性代码:
public string StudentName
{
get
{
return studentName;
}
set
{
studentName = value;
}
}
在VB:
Private _studentName As String
在行末(字符串之后)按下,确保在开头放置_(下划线),因为它将在属性的末尾添加数字:
Ctrl + R + E
相同的窗口将出现:
点击Apply或按ENTER,它将生成以下属性代码,结尾是这样的数字:
Public Property StudentName As String
Get
Return _studentName
End Get
Set(value As String)
_studentName = value
End Set
End Property
数字属性是这样的:
Private studentName As String
Public Property StudentName1 As String
Get
Return studentName
End Get
Set(value As String)
studentName = value
End Set
End Property
在visual studio 2017社区中,键为ctrl +。
我认为Alt+R+F是从变量声明中创建属性的正确方法
我喜欢在IDE中编写一些变量,比如:
private int id;
private string name;
private string version;
private string description;
private string status;
private string symbol;
注意,变量名以小写字母开头,然后选择整个块,并按Ctrl+R, Ctrl+E, Apply。属性是用大写字母生成的:
public int Id
{
get
{
return id;
}
set
{
id = value;
}
}
etc.
去
工具>>选项>>文本编辑器>> c# >>智能感知
在Snippets行为部分:
确保选中了“始终包含代码片段”。
我希望这对你也有用。