声明中 Method1 和 Method2 有什么区别?
方法1
private readonly CategoryBusiness _categoryBusiness = new CategoryBusiness();
方法2
private readonly CategoryBusiness _categoryBusiness;
public CategoryController() : this(new CategoryBusiness())
{
}
public CategoryController(CategoryBusiness categoryBusiness)
{
_categoryBusiness = categoryBusiness;
}
更新: 我的确切问题是
在声明中初始化只读字段是否与在构造函数中使用相同的值初始化它相同?