Friday, June 15, 2012

Creating a list of double string items

Situation:
You can to create a List object to save two different string values, without using string splits or substrings.

Solution:
Use the KeyValuePair structure.

 public List<KeyValuePair<string, string>> GetAllTimeZones()
        {
            List <KeyValuePair<string, string>> timeZones = new List<KeyValuePair<string, string>>();
            timeZones.Add(new KeyValuePair<string, string>(string1, string2));
            }
            return timeZones;
        }


To retrieve data:
foreach (KeyValuePair<string, string> currentTimeZone in GetAllTimeZones())
                {
                    ddlTimeZones.Items.Add(new ListItem(currentTimeZone.Key, currentTimeZone.Value));
                }

No comments:

Post a Comment