是否有从构造函数输入创建字段/属性的快捷方式?(c#)
假设您在新创建的类中有一个构造函数:是否有从构造函数输入创建字段/属性的快捷方式?(c#),c#,C#,假设您在新创建的类中有一个构造函数: public MyClass( string input1, float input2) { } 有没有一种捷径可以产生类似的代码 public string Input1 {get; set;} public float Input2 {get; set;} public MyClass(string input1, float input2) { Input1 = input1; Input2 = input2; } 非常感谢。vi
public MyClass( string input1, float input2)
{
}
有没有一种捷径可以产生类似的代码
public string Input1 {get; set;}
public float Input2 {get; set;}
public MyClass(string input1, float input2)
{
Input1 = input1;
Input2 = input2;
}
非常感谢。visual studio可能会帮助您解决一些问题 当构造函数还不存在时,它就工作了 仅键入:
SomeClass a = new SomeClass(input1, input2);
它将以红色下划线,因为构造函数还不存在。
然后右键单击尚未存在的构造函数并单击
生成=>Construcotr
结果如下所示:
string input1;
float input2;
public SomeClass(string input1, float input2)
{
// Some comment i dont remember
this.input1 = input1;
this.input2 = input2;
}
编辑此功能可能仅存在于高级/终极版中。不确定。visual studio可能会帮助您解决一些问题 当构造函数还不存在时,它就工作了 仅键入:
SomeClass a = new SomeClass(input1, input2);
它将以红色下划线,因为构造函数还不存在。
然后右键单击尚未存在的构造函数并单击
生成=>Construcotr
结果如下所示:
string input1;
float input2;
public SomeClass(string input1, float input2)
{
// Some comment i dont remember
this.input1 = input1;
this.input2 = input2;
}
编辑此功能可能仅存在于高级/终极版中。不确定。visual studio可能会帮助您解决一些问题 当构造函数还不存在时,它就工作了 仅键入:
SomeClass a = new SomeClass(input1, input2);
它将以红色下划线,因为构造函数还不存在。
然后右键单击尚未存在的构造函数并单击
生成=>Construcotr
结果如下所示:
string input1;
float input2;
public SomeClass(string input1, float input2)
{
// Some comment i dont remember
this.input1 = input1;
this.input2 = input2;
}
编辑此功能可能仅存在于高级/终极版中。不确定。visual studio可能会帮助您解决一些问题 当构造函数还不存在时,它就工作了 仅键入:
SomeClass a = new SomeClass(input1, input2);
它将以红色下划线,因为构造函数还不存在。
然后右键单击尚未存在的构造函数并单击
生成=>Construcotr
结果如下所示:
string input1;
float input2;
public SomeClass(string input1, float input2)
{
// Some comment i dont remember
this.input1 = input1;
this.input2 = input2;
}
编辑此功能可能仅存在于高级/终极版中。不确定。考虑到示例中的字段(它们实际上是属性)是公共的,实际上不需要构造函数。您可以在构造新实例时初始化它们:
var x = new SomeClass { input1 = "value1", input2 = 12345 };
考虑到示例中的字段(它们实际上是属性)是公共的,实际上不需要构造函数。您可以在构造新实例时初始化它们:
var x = new SomeClass { input1 = "value1", input2 = 12345 };
考虑到示例中的字段(它们实际上是属性)是公共的,实际上不需要构造函数。您可以在构造新实例时初始化它们:
var x = new SomeClass { input1 = "value1", input2 = 12345 };
考虑到示例中的字段(它们实际上是属性)是公共的,实际上不需要构造函数。您可以在构造新实例时初始化它们:
var x = new SomeClass { input1 = "value1", input2 = 12345 };
还没有。等着C#6出来吧。反对票怎么了?还没有。等着C#6出来吧。反对票怎么了?还没有。等着C#6出来吧。反对票怎么了?还没有。等到C#6出来。否决票是怎么回事?2013年VS Professional为我工作2013年VS Professional为我工作2013年VS Professional为我工作2013年VS Professional为我工作