本文介绍了收集被修改;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

嘿伙计们,我收到的是一个收藏品被修改过;枚举操作可能无法执行。错误。 Everyting工作正常并且保存我只是得到了错误仍然是错误的。

  public   static   void  addItem(SocketUser用户,SocketGuild公会,Item项目, int 金额)
{
checkUser(用户,公会);
if (getItemList(guild).ContainsKey(item.Id)){
List< localItem> inventory = getPlayerInventory(user,guild);
List< string> playerList = getInventoryList(guild);
if (inventoryContains(item,inventory)){
localItem local = new localItem();
local = getLocalItem(inventory,item);
inventory.Remove(getLocalItem(inventory,item));
local.amount + =金额;
inventory.Add(local);
}
else
{
localItem local = new localItem();
local.item = item;
local.amount + =金额;
inventory.Add(local);
}
foreach string line in playerList)
{
if (line.Contains(user.Id.ToString()))
{
string newline = embedInventoryString(user.Id.ToString(),inventory);
playerList.Remove(line);
playerList.Add(换行符);
File.WriteAllLines( server data \\inventoryData + guild.Id。 ToString()+ .json,playerList);
Console.WriteLine( done 2);
}
}
}
}





我尝试了什么:



我试过移动File.WriteAllLines,因为我认为它只是在错误的时间被修改,我没看到代码有什么问题?

解决方案



Hey guys, I'm getting a Collection was modified; enumeration operation may not execute. error. Everyting is working fine and saving i just get spat that error still.

public static void addItem(SocketUser user, SocketGuild guild, Item item, int amount)
{
    checkUser(user, guild);
    if (getItemList(guild).ContainsKey(item.Id)) {
        List<localItem> inventory = getPlayerInventory(user, guild);
        List<string> playerList = getInventoryList(guild);
        if (inventoryContains(item, inventory)) {
            localItem local = new localItem();
            local = getLocalItem(inventory, item);
            inventory.Remove(getLocalItem(inventory, item));
            local.amount += amount;
            inventory.Add(local);
        }
        else
        {
            localItem local = new localItem();
            local.item = item;
            local.amount += amount;
            inventory.Add(local);
        }
        foreach (string line in playerList)
        {
            if (line.Contains(user.Id.ToString()))
            {
                string newline = embedInventoryString(user.Id.ToString(), inventory);
                playerList.Remove(line);
                playerList.Add(newline);
                File.WriteAllLines("server data\\inventoryData" + guild.Id.ToString() + ".json", playerList);
                Console.WriteLine("done 2");
            }
        }
    }
}



What I have tried:

I've tried moving the File.WriteAllLines around because i was thinking it was just being modified at the wrong time, i don't see anything wrong with the code?

解决方案



这篇关于收集被修改;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 23:15