这个集合怎么处理
List<string> list1 = new List<string>(){"02","04","05","11","16","03","05"}
如何提取上面集合中比05大的元素
------解决方案--------------------static void Main(string[] args)
{
List<string> list1 = new List<string>() { "02", "04", "05", "11", "16", "03", "05" };
foreach (string l in list1)
{
int i = int.Parse(l);
if (i > 5)
{
Console.WriteLine(i);
}
}
Console.ReadKey();
}
------解决方案--------------------
List1.Where(x=>x>"05").Select(v=>v).ToList();
------解决方案--------------------List1.Where(x=>Convert.ToInt32(x)>5).Select(x=>x.ToString().PadLeft(2,'0')).ToList();
------解决方案--------------------我的答案是
List<string> list1 = new List<string>() { "02", "04", "05", "11", "16", "03", "05" };
ArrayList marr = new ArrayList();
marr.Add(list1.Where(x => int.Parse(x) >= 05).Select(v => v).ToList());
------解决方案-------------------- ArrayList marr = new ArrayList();
是给你测试结果的,调试后的结果。
marr.Add(list1.Where(x => int.Parse(x) > 05).Select(v => v).ToList());
------解决方案--------------------List<string> list1 = new List<string>() { "02", "04", "05", "11", "16", "03", "05" };
List<string> results = list1.Where(x => x.CompareTo("05") > 0).ToList();