日期:2014-05-17  浏览次数:20981 次

如何用List类实现像combox那样,包含有显示值和实际值的数组
例如
下面的
显示值   值
张三      1
李四      2
........等等

------解决方案--------------------
List可以是包含键 和 值 的类的对象的集合

还可以利用字典来实现
------解决方案--------------------
List<Tuple<string, int>>
List<KeyValuePair<string, int>>
List<MyClass> (class MyClass { public string text; public string value; })
List<string[]>
...
------解决方案--------------------
用泛型就可以了,
自己定义一个类
 public class Student
        {
            private string name;

            public string Name
            {
                get { return name; }
                set { name = value; }
            }
            private string value;

            public string Value
            {
                get { return this.value; }
                set { this.value = value; }
            }
        }

 List<Student> list = new List<Student>();
            Student stu = new Student();
            stu.Name = "zhangsan";