Using DataGridViewRowCollection object in LINQ

后端 未结 1 808
野的像风
野的像风 2020-12-10 01:18

I\'d like to use a DataGridViewRowCollection in a LINQ expression using extension methods and lambda expressions. Unfortunately, the extension methods are for t

相关标签:
1条回答
  • 2020-12-10 01:37

    Yes, do this:

    var rows = yourDataGridViewRowCollection
                   .Cast<DataGridViewRow>()
                   .Where(row => row.index > 4);
    

    This uses the Enumerable.Cast extension method:

    The Cast<TResult>(IEnumerable) method enables the standard query operators to be invoked on non-generic collections by supplying the necessary type information. For example, ArrayList does not implement IEnumerable<T>, but by calling Cast<TResult>(IEnumerable) on the ArrayList object, the standard query operators can then be used to query the sequence.

    0 讨论(0)
提交回复
热议问题