我正在爲我的任務寫一個自定義字典類,但它給錯誤。這個班有什麼問題?謝謝爲什麼這個自定義字典類不工作 - 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