gpt4 book ai didi

c# - 字典中的 "An item with the same key has already been added"

转载 作者:行者123 更新时间:2023-11-30 13:32:21 27 4
gpt4 key购买 nike

我的 C# 代码有问题。我不断收到错误消息“已添加具有相同 key 的项目”,我尝试了网上建议的各种方法,但似乎无法摆脱它。有人可以帮忙吗?我在这一行收到错误

ExistIncInsList.Add(WSIncInstOutput[Insrow][0], Int32.Parse(WSIncInstOutput[Insrow][1]));

下面是涉及此的代码部分。

卡拉波

Dictionary<string, int> ExistIncInsList = new Dictionary<string, int>();
for (int Insrow = 2; Insrow < WSIncInstOutput.Count(); Insrow++)
{
int existincWSInsID = Int32.Parse(WSIncInstOutput[Insrow][1]);
if (!ExistIncInsList.ContainsKey(WSInsName))
{
ExistIncInsList.Add(WSIncInstOutput[Insrow][0], Int32.Parse(WSIncInstOutput[Insrow][1]));
}
if (MaxIncIndID < existincWSInsID)
{
MaxIncIndID = existincWSInsID;
if (MaxIncIndID > MaxIndID)
{
MaxIndID = MaxIncIndID;
}
}
}

if (ExistIncInsList.ContainsKey(WSInsName))
{
WSInsID = ExistIncInsList[WSInsName];
}
else
{
WSInsID = MaxIndID + 1;
MaxIndID++;
}

最佳答案

检查正确的 key :

if (!ExistIncInsList.ContainsKey(WSIncInstOutput[Insrow][0]))

代替:

if (!ExistIncInsList.ContainsKey(WSInsName))

关于c# - 字典中的 "An item with the same key has already been added",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14606933/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com