views:

45

answers:

2

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]);
        }
    }
}
+1  A: 

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

SLaks
Which is totally AWESOME! We should all write more code like this...
Jimmy Hoffa
+3  A: 

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