C#使用静态类属性,就像它们是已命名空间一样?

问题描述 投票:-1回答:1

我正在尝试创建一个类来保存我的所有全局常量,例如:

namespace MyProj
{
    public static class Constants
    {
        public const string MY_STRING = "this needs to be used ad nauseum";
    }
}

这很好。但是,结果是我必须始终在代码中键入:

doSomethingWith(Constants.MY_STRING);

[我真正想做的事是去(类似):

using MyProj.Constants;
doSomethingWith(MY_STRING);

我该如何实现?

c# namespaces using
1个回答
3
投票
using static MyProj.Constants;

详细信息here

© www.soinside.com 2019 - 2024. All rights reserved.