C# 静态字典在抽象类 .NET 2.0 中声明和初始化
我有一个抽象类,想添加一个错误代码的静态字典。我尝试了以下方法:
public abstract class Base
{
...
protected static readonly Dictionary<int, string> errorDescriptions = new Dictionary<int, string>()
{
{ 1, "Description1"},
{ 2, "Description2"},
...
};
...
}
但后来发现这是在.NET 3.0中实现的;我用的是2.0。我环顾四周,其他一些人建议我在构造函数中添加对,但这是一个抽象类。
我如何/应该填充字典?
谢谢。
I have an abstract class and would like to add a static dictionary for error codes. I tried the following:
public abstract class Base
{
...
protected static readonly Dictionary<int, string> errorDescriptions = new Dictionary<int, string>()
{
{ 1, "Description1"},
{ 2, "Description2"},
...
};
...
}
but then discovered that this was implemented in .NET 3.0; I am using 2.0. I looked around and some others suggested I add the pairs in the constructor but this is an abstract class.
How can/should I populate the dictionary?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)