我有以下类:的对象有关Static关键字发行面向对象编程
public abstract class TMSPageBaseClass : System.Web.UI.Page
{
protected DevExpress.Xpo.Session XpoSession;
}
public class CommonUtility : TMSPageBaseClass
{
protected static t_rolepermissions GetPermissions()
{
//here I want to access the variable XpoSession defined in abstract class, I tried
this.XpoSession //it throws an error saying: Keyword this is not valid in a static Property,
}
}
那么,如何可以访问继承类变量为静态函数吗?
为什么GetPermissions()必须是静态的? – jolySoft 2012-01-18 11:07:14
请使用不正确的语言来做** not **标签。这不是C或C++。 – Oded 2012-01-18 11:07:24
是的,您无法从静态方法访问实例成员。为什么你首先要使用静态方法? – Groo 2012-01-18 11:07:39