我有两个构造函数,它们将值提供给只读字段.
public class Sample
{
public Sample(string theIntAsString)
{
int i = int.Parse(theIntAsString);
_intField = i;
}
public Sample(int theInt) => _intField = theInt;
public int IntProperty => _intField;
private readonly int _intField;
}
Run Code Online (Sandbox Code Playgroud)
一个构造函数直接接收值,另一个构造函数进行一些计算并获取值,然后设置字段.
现在这里是抓住:
有任何想法吗?