C# Dictionary修改遇到的一个错误 out of sync!
来源:互联网 发布:淘宝和拼多多哪个货真 编辑:程序博客网 时间:2024/05/20 05:08
题目中问题是我批量修改字典的数据时遇到的问题,作为小白真是发现好多东西没有接触到啊。
上错误代码
//foreach (KeyValuePair<string,float> item in dataDic)
//{
// for (int i = 0; i < cars.Length; i++)
// {
// if (cars[i].name.Contains(item.Key))
// {
// dataDic[item.Value.ToString()] = cardatas[i].currentScore;
// break;
// }
// }
//}
错误提示
InvalidOperationException: out of sync
System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Single].VerifyState () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:912)
System.Collections.Generic.Dictionary`2+Enumerator[System.String,System.Single].MoveNext () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:835)
RaceData.Updatedatas () (at Assets/Scripts/Data/RaceData.cs:164)
RaceData.Update () (at Assets/Scripts/Data/RaceData.cs:80)
网上一顿搜集资料,说是不能用迭代去修改Dictionary,需要先把字典作为一个Buffer引出来,然后修改Buffer
上代码
List<string> buffer = new List<string>(dataDic.Keys);
foreach (string item in buffer)
{
for (int i = 0; i < cars.Length; i++)
{
if (cars[i].name.Contains(item))
{
dataDic[item.ToString()] = cardatas[i].currentScore;
break;
}
}
}
//这样就好使了,当然还有其他方法修改
- C# Dictionary修改遇到的一个错误 out of sync!
- Unity在Dictionary中删除修改元素时出现InvalidOperationException: out of sync
- PHP 开发中遇到的 Commands out of sync; you cant't run this command now 错误 解决方法
- C#报错:InvalidOperationException: out of sync
- Unity3D -- C#之InvalidOperationException: out of sync
- snapshot out of sync
- 解决maven clean install后tomcat启动项目提示“is out of sync”的错误
- C# 连接Mysql报错 Out of sync with server
- 遇到的一个"String index out of range" 问题
- Eclipse在搜索的时候,遇到Resource is out of sync with the file system的问题
- out-of-sync in juno
- [Unity3D]InvalidOperationException: out of sync
- mysql Commands out of sync
- MyEclipse导出项目时发生的错误:Resource is out of sync with the file system解决办法
- VC开发MySql二 (Commands out of sync的解决方案)
- dbca安装oracle的时候遇到上面的错误 ORA-27102: out of memory
- Eclipse报resource is out of sync with the file system错误
- 解决导出jar时发生错误:Resource is out of sync with the filesystem
- iphone常用控件之UIScrollView
- 可以将资源移动到相同的域名上或者启用 CORS 来解决这个问题(跨域问题)、options请求报错
- Git的一些命令
- 数据库技术
- Python import .pyd 可能遇到路径的问题
- C# Dictionary修改遇到的一个错误 out of sync!
- HTML介绍及运行原理
- Effective JAVA NO1考虑用静态工厂方法代替构造器
- Mutiple HDU5211(筛法)
- 第四章第4题
- c++作业 重载
- 尚能饭否?
- codeforces 538c
- Swipebacklayout及Activity启动的动画