2

我正在查看一个代码块,无法理解该行发生了什么 - 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]);
        }
    }
}
4

2 回答 2

7

我的猜测是这样的事情是有意的:

if (formValues.AllKeys.Contains("Email_" + i)) {
    if (locations.Emails.Count > i)
    {
        locations.Emails[i] = formValues["Email_" + i];
    }
    else
    {
        locations.Emails.Add(formValues["Email_" + i]);
    }
}
于 2010-08-31T14:39:56.710 回答
1

此行检查AllKeys集合是否包含"Email_" + i,但不对结果做任何事情。

于 2010-08-31T14:37:44.493 回答