0

I have a collection of key-value pairs that are being returned by post to which I am adding to a list. I would like to append a value based upon the key. In the example below, the for loop appends the key and calls a function (Boolean) that appends either a yes or no depending on the value.

What I would like to do is check the key name and IF the key begins with "chk" perform the loop below, ELSE IF, the key begins with anything else, I would like to append the value to the key.

I'm not sure how to reference the value of the key in code. Thanks in advance.

        for (int i = 0; i < newKeys.Length; i++ )
        {
            sb.Append(newKeys[i] + ",\"" + Boolean(fc[newKeys[i]]) + "\",<br />");
        }
tereško
  • 58,060
  • 25
  • 98
  • 150
Susan
  • 1,822
  • 8
  • 47
  • 69

1 Answers1

0

Is newKeys a generic Dictionary<>?

if so, you could...

        Dictionary<string, string> newKeys = new Dictionary<string, string>();
        newKeys.Add("chkOne", "some text");

        foreach (var s in newKeys)
        {
            if (s.Key.Contains("chk"))
            {
                //do something
            }
        }
Ryand.Johnson
  • 1,906
  • 2
  • 16
  • 22