日期:2014-05-18  浏览次数:20962 次

请问,如何将listBox1的Items转换成List<T>
请问,如何将listBox1的Items转换成List<T>,
我需要使用List<T>的查询方法,需要查询满足谓词函数条件的元素
比如,Exists方法、Find方法.......等等


------解决方案--------------------
C# code

var data=this.listBox1.Items.Cast<string>().ToList();

------解决方案--------------------
listBox1.Items装的是什么东东啊? 把他拿出来,构造成T对象,然后在放入List<T>中不就行了
------解决方案--------------------
C# code
List<string> strList = new List<string>();
            foreach (string item in listBox1.Items)
            {
                strList.Add(item);
            }

------解决方案--------------------
this.listBox1.Items.Items.OfType<T>()

或者
this.listBox1.Items.Items.Cast<T>()

T与你当初设定的对象有关,请自己看着办
------解决方案--------------------
C# code
Class1[] clsarr = new Class1[listBox1.Items.Count];
listBox1.Items.CopyTo(clsarr, 0);
List<Class1> list = new List<Class1>(clsarr);

------解决方案--------------------
探讨
请问,如何将listBox1的Items转换成List<T>,
我需要使用List<T>的查询方法,需要查询满足谓词函数条件的元素
比如,Exists方法、Find方法.......等等