0
當我注意到我的foreach循環無法上傳文件列表並且for循環沒有工作時,我正在使用我的網站。我很想知道for循環的工作原理和foreach循環的原因。上傳文件時出現Casting錯誤
我得到的錯誤消息是:無法將system.string轉換爲xx。
所以這些都是循環我有:
HttpFileCollection documentsList = Request.Files;
// Doesn't
foreach (var file in documentsList.Cast<HttpPostedFile>())
{
var test = file;
}
// Doesn't
foreach (var file in documentsList)
{
var test = (HttpPostedFile)file;
}
// Works
for (int i = 0; i < documentsList.Count; i++)
{
var file = (HttpPostedFile) documentsList[i];
}
提前感謝!
啊謝謝!我不知道 – Jamie