foreach(string file in strAllFiles)
{
foreach(char c in file)
{
if (c > 127)
{
using (SqlConnection con = new SqlConnection(CS))
{
con.Open();
SqlCommand sqlcom = new SqlCommand("sp_ReplaceNonAsciiCharset", con);
sqlcom.CommandType = CommandType.StoredProcedure;
SqlParameter sqlparam = new SqlParameter();
sqlparam.ParameterName = "@non_ascii_char";
sqlparam.Direction = ParameterDirection.Input;
sqlparam.SqlDbType = SqlDbType.NChar;
sqlparam.Size = 2;
sqlparam.Value = c;
sqlcom.Parameters.Add(sqlparam);
object o = sqlcom.ExecuteScalar();
int i = file.IndexOf(c);
file1 = file.Remove(i, 1);
file2 = file1.Insert(i, o.ToString());
file = file2;
}
}
}
}
在最後一行file=file2
,我得到的錯誤:的foreach迭代變量錯誤是給
cannot assign to file because it is a foreach iteration variable
請明確說明你打算做什麼!如果你不指定你想要做什麼,我們不能幫助解決它! –
檢查http://stackoverflow.com/questions/3551696/why-cant-i-modify-the-loop-variable-in-a-foreach – link64
該錯誤是相當自我解釋..你試圖分配一個值到「foreach」迭代的一部分的變量。 –