了解 FormCollection.AllKeys.Contains

发布于 2024-09-16 21:01:50 字数 553 浏览 4 评论 0原文

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

I'm looking at a code block and can't grok what's happening with the line - formValues.AllKeys.Contains("Email_" + i); it looks like an assignment should be taking place but...

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]);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ双果 2024-09-23 21:01:50

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

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

My guess is that something like this was intended:

if (formValues.AllKeys.Contains("Email_" + i)) {
    if (locations.Emails.Count > i)
    {
        locations.Emails[i] = formValues["Email_" + i];
    }
    else
    {
        locations.Emails.Add(formValues["Email_" + i]);
    }
}
星星的軌跡 2024-09-23 21:01:50

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

This line checks whether AllKeys collection contains "Email_" + i, but doesn't do anything with the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文