[英]Why can't I access public property field in static class
I'm trying to figure out why this is not working... 我试图弄清楚为什么这不起作用...
public static class ApplicationType
{
private static ApplicationEnum application = ApplicationEnum.App1;
public static ApplicationEnum Application
{
get { return application; }
set { application = value; }
}
public enum ApplicationEnum
{
App1,
App2,
App3
}
}
I want to access Application
from another class, such as... 我想从另一个类访问Application
,例如...
public partial class MainWindow : Window
{
ApplicationType. //<-- Intellisense shows only ApplicationEnum }
Thanks. 谢谢。
EDIT: Problem was that I was not trying inside the MainWindow as in this example as I thought I was. 编辑:问题是我没有像本例中那样尝试在MainWindow内部尝试。
You're in the middle of a class declaration. 您处于类声明的中间。 You need to declare a field, method etc. For example, this should be fine (if you make ApplicationEnum
public): 您需要声明一个字段,方法等。例如,这应该很好(如果您将ApplicationEnum
公开):
private ApplicationEnum foo = ApplicatoinType.Application;
Until you've made ApplicationEnum
public, you'll find that your Application
property will fail to compile - you can't declare a public property of a type which isn't itself public. 在将ApplicationEnum
公开之前,您会发现Application
属性将无法编译-您无法声明本身不是公共类型的公共属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.