我已经习惯了许多Java (Eclipse、NetBeans和IntelliJ IDEA)为您提供一个命令,以便根据类中的字段为类生成默认构造函数。
例如:
public class Example
{
public decimal MyNumber { get; set; }
public string Description { get; set; }
public int SomeInteger { get; set; }
// ↓↓↓ This is what I want generated ↓↓↓
public Example(decimal myNumber, string description, int someInteger)
{
MyNumber = myNumber;
Description = description;
SomeInteger = someInteger;
}
}
让构造函数填充对象的所有字段在大多数OOP语言中都是很常见的任务,我假设有一种方法可以节省我用C#编写这些样板代码的时间。我是C#世界的新手,所以我想知道我是不是错过了这门语言的一些基础知识?在Visual Studio中是否有一些显而易见的选项?
https://stackoverflow.com/questions/2976363
复制相似问题