伙计们,我有一个问题,
如果我有一系列的方法,例如:
Main()
{
Method1();
}
Method1()
{
Method2();
}
Method2()
{
Method3();
}
Method3()
{
ObtainsUserPermission(httpContext.Current.User.Name);
}最好的方法是怎么做呢?在最后一个Method3中使用参数"httpContext.Current.User.Name“,还是在每个方法中传递参数?如下所示:
Main()
{
Method1(httpContext.Current.User.Name);
}
Method1(string name)
{
Method2(name);
}
Method2(string name)
{
Method3(name);
}
Method3(string name)
{
ObtainsUserPermission(name);
}谢谢你所做的一切
发布于 2011-08-17 16:39:00
这闻起来像是神奇的参数。
一个很好的经验法则是-如果您希望method3()的执行依赖于该名称,请将该名称作为参数传递。一般来说,你不应该在函数中使用全局变量。它可能会变得很难调试和维护。一个例外是类的成员,在这种情况下,您的成员在方法中是可见的,并且不需要将它们作为参数传递。
https://stackoverflow.com/questions/7089881
复制相似问题