我有一个List <List <string >>,需要过滤内部List。看起来像这样:
{["/DownloadFile2.aspx?File=1026704PR20131001.PDF","10/1/2013 | Monthly Memo","10/1/2013","","","CI","","","","","",""],
["/DownloadFile2.aspx?File=1026704PR20141001.PDF","10/1/2014 | Monthly Memo","10/1/2014","","","CC","","","","","",""],
["/DownloadFile2.aspx?File=1026704date20130928.PDF","9/30/2013 | New Memo","9/30/2013","","","CC","","","","","",""],
["/DownloadFile2.aspx?File=1026704date20140928.PDF","9/30/2014 | New Memo","9/30/2014","","","CI","","","","","",""]}
如何使用LINQ .Where子句过滤第二列?
就像过滤术语“每月”将返回:
{["/DownloadFile2.aspx?File=1026704PR20131001.PDF","10/1/2013 | Monthly Memo","10/1/2013","","","CI","","","","","",""],
["/DownloadFile2.aspx?File=1026704PR20141001.PDF","10/1/2014 | Monthly Memo","10/1/2014","","","CC","","","","","",""]}
添加代码
我的Web服务中的存档定义:
[DataContract(Namespace = "http://www.mysite.com")]
public class Archive
{
[DataMember]
public List<string> Header {get; set;}
[DataMember]
public List<List<string>> Rows{get; set;}
}
从服务获取存档的代码(mps是Web服务)
/// param contains values used to retrieve a partial set
/// as well as other values used to pass data to jQuery DataTable
///
Archive docs = mps.GetArchiveArray(LogonTicket, PID, param.iDisplayStart, param.iDisplayLength, "D");
List<List<string>> filteredRows;
// If the params sSearch value is not null or empty, filter the results
// else return the full results
if (!string.IsNullOrEmpty(param.sSearch))
{
// Here's where I need to filter the result set based on the params.sSeach value.
filteredRows = docs.Rows.?????;
}
else
{
filteredRows = docs.Rows;
}
然后将filterRows通过循环传递,以使用StringBuilder构建我的JSON,然后将所需的完整结果作为JSON发送:
string result = sb.ToString();
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = numDocs,
iTotalDisplayRecords = numDocs,
aaData = result
},
JsonRequestBehavior.AllowGet);
使用Select
外部列表中的子句,例如:
outerList.Select(inr => inr.Where(...))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句