0

こんにちは、List
ListClass[0] = (0,2)
ListClass[1] = (0,3)
ListClass[2] = (0,8)
ListClass[3] = (1,0)
ListClass[ 4] = (1,1)
ListClass[5] = (2,1)
ListClass[6] = (3,0)
ListClass[7] = (3,1)
ListClass[8] = (3,3)
ListClass[ 9] = (3,8)

public class ListClass
{
    public int rowIndex { get; set; }
    public int columnIndex { get; set; }
    public ListClass()
    {
    }
    public ListClass(int row, int column)
    {
        this.rowIndex = row;
        this.columnIndex = column;
    }
}

次の条件のリストから一番上の結果の RowNumber を取得できる Linq クエリを手伝ってください。

ListClass.rowIndex >= 0 および ListClass.columnIndex > 4 つまり

、与えられた例によれば、結果は2でなければなりません。

4

1 に答える 1

2

使いたいようですねList<T>.FindIndex

int index = list.FindIndex(x => x.rowIndex >= 0 && x.columnIndex > 4);

そのような値がない場合、これは-1を返します。

従来のプロパティはPascalCasedであるため、これらはとである必要があることに注意してRowIndexくださいColumnIndex

于 2012-08-06T07:58:04.793 に答える