C#使用静态类属性,就好像它们是按名称命名的一样



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

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);

我怎样才能做到这一点?

static添加到using:

using static MyProj.Constants;

详细信息请点击此处。

相关内容

最新更新