我有一個List<bool>
。我需要獲得項目值= true的前n個項目的索引。Lambda表達式有條件地獲取列表項的索引
例如,下面的列表項(布爾)
10011001000
TopTrueIndexes(3) = The first 3 indexes where bits are true are 0, 3, 4
TopTrueIndexes(4) = The first 4 indexes where bits are true are 0, 3, 4, 7
我怎麼能寫這樣的拉姆達?
不錯,我不知道你可以做Select((val,ind)=> ...)。 +1 – Alxandr 2010-11-13 21:15:56
@Alxandr:這可以通過直接調用Select方法來完成,但不能通過查詢表達式來完成。 – 2010-11-13 21:18:53
@Jon。非常好,謝謝。 – Jimmy 2010-11-13 21:19:35