Class to format a Query String

The following is a class that will format a string as a querystring:

public class QueryStringFormatter {
  private Dictionary<stringstring> _Items = new Dictionary<stringstring>();
  public Dictionary<stringstring> Items {
    get { return _Items; }
    set { _Items = value; }
  }
  public override string ToString() {
    string retVal = string.Empty;
    if (_Items.Count > 0) {
      List<string> list = new List<string>();
      foreach (KeyValuePair<stringstring> kvp in _Items) {
        list.Add(string.Format("{0}={1}", kvp.Key, kvp.Value));
      }
      retVal = "?" + string.Join("&", list.ToArray());
    }
    return retVal;
  }
}

Comments are closed.