我正在为我的任务写一个自定义字典类,但它给错误。这个班有什么问题?谢谢为什么这个自定义字典类不工作 - C#4.0
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);
}
}
}
* *什么错误?它在哪里?你有例外吗?它没有按预期执行吗?不要让我们成为侦探。 – 2012-02-15 00:50:31
添加了错误图像。请刷新并重新检查 – MonsterMMORPG 2012-02-15 00:53:56
您是否知道只需单击该错误并按F1即可获取此帮助页面? [编译器错误CS1612](http://msdn.microsoft.com/en-us/library/wydkhw2c(v = vs.100).aspx) – 2012-02-15 00:59:35