解决方案 »

  1.   


    StringBuilder sbList = new StringBuilder();
    for (int i = 0; i < this.Count; i++)
    {
    if (i == 0) 
    {
    sbList.AppendFormat("{0}={1}",  this.GetKey(i), this.Get(i));
    }
    else 
    {
    sbList.AppendFormat("&{0}={1}", this.GetKey(i), this.Get(i));
    }
    }你是在拼接url吧
      

  2.   

    是this.GetKey的问题吧,跟进去看看
      

  3.   


            object[] var = { 1, "1" };
            StringBuilder sbList = new StringBuilder();
            sbList.AppendFormat("{0}={1}", var);
            string str = sbList.ToString();这样,没问题的,2楼说,调试试一下,看看
      

  4.   

    GetKey 和 Get是做什么的?
      

  5.   

                StringBuilder sbList = new StringBuilder();
                for (int i = 0; i < 10; i++)
                {
                    object[] var = { i, i*10 };
                    if (i == 0) sbList.AppendFormat("{0}={1}", var);
                    else sbList.AppendFormat("&{0}={1}", var);
                }这样可以测试通过 vs2010
      

  6.   


    using System;
    using System.Text;
    using System.Globalization;
    using System.Collections.Specialized;namespace abc
    {
        public class test : NameValueCollection
        {
            public test() { }        public string this[string name, int index] { get { return this.Get(index); } set { this.BaseAdd(name, value); } }        public void Add(string name, string value, int index)
            {
                this[name, index] = value;
            }        public void Decode(string str)
            {
                this.Clear();
                string[] a = str.Split('&'); //这里也是报同样错误
                for (int i = 0; i < a.Length; i++)
                {
                    string[] item=a[i].Split('=');
                    if (item.Length > 1)
                    {
                        this.Add(item[0], item[1], i);
                    }
                }
            }        public string Encode()
            {
                if (this.Count < 1) return null;
                StringBuilder sbList = new StringBuilder();
                for (int i = 0; i < this.Count; i++)
                {
                    object[] var = { this.GetKey(i), this.Get(i) }; //这里也是报同样错误
                    if (i == 0) sbList.AppendFormat("{0}={1}", var);
                    else sbList.AppendFormat("&{0}={1}", var);
                }
                return sbList.ToString();            //string str = "";
                //for (int i = 0; i < this.Count; i++)
                //{
                //    if (i == 0) str += this.GetKey(i) + "=" + this.Get(i); //这里也是报同样错误
                //    else str += "&" + this.GetKey(i) + "=" + this.Get(i);
                //}
                //return str;
            }        public void Remove(string arrayName, int index)
            {
                base.Remove(this[arrayName,index]);
            }
        }
    }
      

  7.   

    用的是vs2010  .net framework 4.0
    是不是引用NameValueCollection类的问题呢?
      

  8.   

            public string Encode()
            {
                if (this.Count < 1) return null;
                //StringBuilder sbList = new StringBuilder();
                String sbList = null;
                string var0;
                string var1;
                NameValueCollection n = new NameValueCollection();
                for (int i = 0; i < this.Count; i++)
                {
                    //object[] var = { this.GetKey(i), this.Get(i) }; //这里也是报同样错误
                    var0 = n.GetKey(i);//{ this.GetKey(i), this.Get(i) };
                    var1 = n.Get(i);
                    if (i == 0)
                    {
                        sbList += string.Format("{0}={1}", n.GetKey(i), n.Get(i));
                    }
                    else
                    {
                        sbList += string.Format("&{0}={1}", var0, var1);
                    }
                }
                return sbList.ToString();
            }