我正在查看代码块,无法看清该行的内容-formValues.AllKeys.Contains("Email_" + i);似乎应该进行分配,但是...

public ActionResult EditAdditionalLocations(int ID, int? count, FormCollection formValues)
{
    ...

    for (int i = 0; i < _count; i++)
    {
        formValues.AllKeys.Contains("Email_" + i);
        if (locations.Emails.Count > i)
        {
            locations.Emails[i] = formValues["Email_" + i];
        }
        else
        {
            locations.Emails.Add(formValues["Email_" + i]);
        }
    }
}

最佳答案

我的猜测是这样的:

if (formValues.AllKeys.Contains("Email_" + i)) {
    if (locations.Emails.Count > i)
    {
        locations.Emails[i] = formValues["Email_" + i];
    }
    else
    {
        locations.Emails.Add(formValues["Email_" + i]);
    }
}

关于c# - 了解FormCollection.AllKeys.Contains,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3610032/

10-11 13:11