//使用排序字典,默认只支持升序
SortedDictionary<string, string> sd = new SortedDictionary<string, string>();
sd.Add("TransactionID", "110000000001");
sd.Add("ServiceType", "/SMSMT");
// 先将参数以其参数名的字典序升序进行排序
IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(sd);
IEnumerator<KeyValuePair<string, string>> iterator = sortedParams.GetEnumerator();
// 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起
StringBuilder basestring = new StringBuilder();
while (iterator.MoveNext())
{
string key = iterator.Current.Key;
string value = iterator.Current.Value;
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
{
basestring.Append(key).Append("=").Append(value);
}
}