初学Linq,求指教
1.List<string[]> numberList = list as List<string[]>;
var p = numberList.OrderByDescending(s => s[3]).FirstOrDefault();
string[] arrayStr = p as string[];
目的是找出列表中数组第4个值最大的项,这么写有问题吗?
2.List<string[]> list = obj as List<string[]>;
var q = from p in list where Convert.ToDateTime(p[3]) == dt select p;
目的是找列表中数组第4个值等于给定值得项,然后怎么取出string[]类型的这一项呢?
------解决方案--------------------(1)正确,也可以用
var p = numberList.OrderBy(s => s[3]).LastOrDefault();
(2)var q = (from p in list where Convert.ToDateTime(p[3]) == dt select p).First()[4];
------解决方案--------------------lamda,action<t>, function<t>
这几个东西学好了,linq就一个easy job
------解决方案--------------------1、第一个正确
2、var q = (from p in list
where Convert.ToDateTime(p[3]) == dt
select p).FirstOrDefault()[3];