2013-02-07 15 views

回答

9

嘗試:

bool test = MyList.Any(x => x); 

但你必須插入任何內容之前初始化列表。

+2

MyList.Any(x => x == true); 在這種情況下,不要傷害IMO。 – David

4

使用任何

var anyTrue = MyList.Any(i => i); 
+0

很好的答案,謝謝 –

1

如果要列出所有true

List<bool> MyList = new List<bool>(); 
MyList.Add(true); 
MyList.Add(false); 
MyList.Add(false); 
var listTrue = MyList.Where(c => c); 

我不知道,你有什麼實際Class,因爲如果你想.Find是同樣的結果。

var b = MyList.Find(c => c) 

也許你忘了申報varDataType

+0

很好的答案,謝謝 –

0

myList中是布爾的列表

myList中= getSelectedChannels(); List allTrue = myList.FindAll(a => a == true);

allTrue將是符合條件的bool列表(bool爲true)。現在只需說allTrue.Count即可獲取該列表中的項目數量。

相關問題