using System.Collections.Generic;
public static void Main()
string keyToEncode="cart_items[0][name]";
string valueToEncode="Fictional Product name with special characters like ()";
string encodedItem= System.Net.WebUtility.UrlEncode(keyToEncode)+"="+ System.Net.WebUtility.UrlEncode(valueToEncode);
Console.WriteLine("Key/Value pair encoded as {0}", encodedItem);
Console.WriteLine("Key/Value pair decoded as {0}", System.Net.WebUtility.UrlDecode(encodedItem));
var sortedDict = new SortedDictionary<string, string>();
sortedDict.Add(keyToEncode, valueToEncode);
var encodedDictionary = new SortedDictionary<string, string>();
foreach ( var keyValuePair in sortedDict )
var encodedKey = System.Net.WebUtility.UrlEncode( keyValuePair.Key );
var encodedValue = System.Net.WebUtility.UrlEncode( keyValuePair.Value );
encodedDictionary.Add( encodedKey, encodedValue );
Console.WriteLine(string.Join("&", encodedDictionary.Select(x => x.Key + "=" + x.Value)));