静态类System.Configuration.ConfigurationManager的别名;(Alias to static class System.Configuration.Configur

编程入门 行业动态 更新时间:2024-10-24 11:24:06
静态类System.Configuration.ConfigurationManager的别名;(Alias to static class System.Configuration.ConfigurationManager;)

我想声明一个静态类的别名: 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培训"/> &

本文发布于:2023-08-04 12:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   静态   Configuration   ConfigurationManager   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!