【发布时间】:2014-07-31 14:32:37
【问题描述】:
我有一个公开接口的 dll,如下所示:
public Interface IClientGroup
{
IQueryable ClientsGroup {get;}
void Activate(ClientGroup clientgroup);
//many other members and functions
}
在我的控制器类中,它像这样在构造函数中传递:
public ControllerClass(IClientGroup clientgroup)
{
var _clientgroup = clientgroup
}
//later _clientgroup used to access everything in Interface
现在,当我调试时,我看到它在传递给构造函数时,值已经初始化,所以我假设我可以简单地在任何函数中传递 IClientgroup clientgroup 并且它已经初始化但它为空,每次如果我在使用之前声明它并说it is type but used as variable 如果我直接传递给在构造函数中完成的函数。
public UseValues(IclientGroup clientgroup)
{
//error: IClientGroup is type but used as variable
}
如何使用已初始化值的客户端组?我无法从 dll 中看到确切的实现。
【问题讨论】:
-
var _clientgroup = clientgroup在 ctor 内部初始化本地变量,您将无法在课堂的其他地方重用它。为此使用私有字段或属性 -
这几乎是 OOP 101。在深入研究之前,您可能需要花一些时间退后一步,学习一些基本的面向对象编程。
标签: c# asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4