我想声明一个静态类的别名: System.Configuration.ConfigurationManager;
我希望这个别名可用于我班级的所有方法,所以我试图这样做:
public class MyClass { using conf = System.Configuration.ConfigurationManager; public void MethodOne() { string appConfigStr = conf.AppSettings["someAppSettings"].ToString() } }但上面引发了以下错误 :类,结构或接口成员声明中的令牌“使用”无效
我可以做些什么来为这个配置管理器类别名吗?
I would like to declare an alias to the static class : System.Configuration.ConfigurationManager;
I would like this alias to be available to all the methods of my class so I've tried to do that :
public class MyClass { using conf = System.Configuration.ConfigurationManager; public void MethodOne() { string appConfigStr = conf.AppSettings["someAppSettings"].ToString() } }But the above raises the following error : Invalid token 'using' in class, struct, or interface member declaration
Is there something I can do to alias this configuration manager class ?
最满意答案
using指令可用于在当前.cs文件的范围内创建别名。
using conf = System.Configuration.ConfigurationManager; namespace MyNamespace { public class MyClass { public void MethodOne() { string appConfigStr = conf.AppSettings["someAppSettings"].ToString() } } }有关更多信息,请参阅此文档
using directives can be used to create an alias within the scope of the current .cs file.
using conf = System.Configuration.ConfigurationManager; namespace MyNamespace { public class MyClass { public void MethodOne() { string appConfigStr = conf.AppSettings["someAppSettings"].ToString() } } }See this documentation for more information
更多推荐
class,ConfigurationManager,public,Configuration,电脑培训,计算机培训,IT培训"/> &
发布评论