Select method in List Collection

后端 未结 5 1633
温柔的废话
温柔的废话 2021-01-30 15:57

I have an asp.net application, and now I am using datasets for data manipulation. I recently started to convert this dataset to a List collection. But, in some places it doesn\'

5条回答
  •  攒了一身酷
    2021-01-30 16:31

    Generic List have the Where(Func) extension method that can be used to filter data.

    In your case with a row array:

    var rows = rowsArray.Where(row => row["LastName"].ToString().StartsWith("a"));
    

    If you are using DataRowCollection, you need to cast it first.

    var rows = dataTableRows.Cast().Where(row => row["LastName"].ToString().StartsWith("a"));
    

提交回复
热议问题