【发布时间】:2012-03-06 09:13:21
【问题描述】:
我正在为我的任务编写一个自定义字典类,但它给出了错误。这堂课有什么问题?谢谢
public struct MyValue
{
public int irValue1;
public int irValue2;
}
public class csCustomDictionary : Dictionary<string, MyValue>
{
public void Add(string srKey, int irVal1, int irVal2)
{
if (this.ContainsKey(srKey) == true)
{
this[srKey].irValue1 = this[srKey].irValue1 + irVal1;
this[srKey].irValue1 = this[srKey].irValue2 + irVal2;
}
else
{
MyValue val;
val.irValue1 = irVal1;
val.irValue2 = irVal2;
this.Add(srKey, val);
}
}
}
}
这是错误信息
C# 4.0
修改后的版本是否正确
public class csMyValue
{
public int irValue1;
public int irValue2;
}
public class csCustomDictionary : Dictionary<string, csMyValue>
{
public void Add(string srKey, int irVal1, int irVal2)
{
if (this.ContainsKey(srKey) == true)
{
this[srKey].irValue1 = this[srKey].irValue1 + irVal1;
this[srKey].irValue1 = this[srKey].irValue2 + irVal2;
}
else
{
csMyValue val = new csMyValue();
val.irValue1 = irVal1;
val.irValue2 = irVal2;
this.Add(srKey, val);
}
}
}
【问题讨论】:
-
什么错误?它在哪里?你有例外吗?它没有按预期执行吗?不要让我们成为侦探。
-
添加了错误图片。请刷新并重新检查
-
您知道只需单击错误并按 F1 即可获取此帮助页面吗? Compiler Error CS1612
标签: c# class c#-4.0 dictionary custom-attributes