可能重复:
收集已修改; 枚举操作可能无法执行
嗨,您好,
我正在创建一个项目估算程序,并收到以下错误:C#Collection已被修改; 枚举操作可能无法执行.
它与使用它有关:我最初在全球范围内声明了这个:
Dictionary<int, int> rankings = new Dictionary<int, int>();
Run Code Online (Sandbox Code Playgroud)
包含此字典的Next方法执行以下操作:
private void getFirstEstimation()
{
List<int> array = new List<int>();
string strConnection = ConfigurationSettings.AppSettings["ConnectionString"];
MySqlConnection connection = new MySqlConnection(strConnection);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader reader;
command.CommandText = "SELECT idprojects FROM `test`.`projects` WHERE application_layers = " + applicationTiers;
connection.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
array.Add(Convert.ToInt32(reader["idprojects"].ToString()));
}
foreach (int i in array)
{
rankings[i] = 15;
}
connection.Close();
}
Run Code Online (Sandbox Code Playgroud)
我在这里第二次叫它:
private void getSecondEstimation()
{
Dictionary<int, string> sqltext …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的ASP.NET网页后面的C#代码检查服务器上是否有文件.我知道文件确实存在,因为我事先将它放在服务器上的一段代码中.任何人都可以看到为什么它没有找到该文件.这是代码:
wordDocName = "~/specifications/" + Convert.ToInt32(ViewState["projectSelected"]) + ".doc";
ViewState["wordDocName"] = wordDocName;
if (File.Exists(wordDocName))
{
btnDownloadWordDoc.Visible = true;
}
else
{
btnDownloadWordDoc.Visible = false;
}
Run Code Online (Sandbox Code Playgroud)