2012-12-22 12 views
0

我想從列表(字符串)的多個對象中計數''。假設我有三個列表sig1,sig2sig3,它們都包含'是的'或'沒有'。我想從sig1獲得的「」計數,其中sig2是「」和sig3是「沒有」。從列表中的多個對象中獲取「是」的計數<string>

+0

sid1,sig2和sig3的結構是什麼?你試過什麼了? –

+3

你需要澄清這一點,它很難遵循 – Steve

+0

你是什麼意思,其中sig2是'是'和sig3是'否'? –

回答

1

你的問題真的很難理解,但我猜這樣的事情是你想要的。

List<string> myAnswers = new List<string>() { "yes", "yes", "no" }; 
Int32 numberOfPositiveAnswers = myAnswers.Count(x => x.Equals("yes")); 

numberOfPositiveAnswers值將被2.

+0

列表 sig1 =新列表(); 列表 sig2 =新列表(); 列表 sig3 =新列表(); 這裏是三個列表對象,它們包含成千上萬的'是'和'不是'...我希望sig1的計數是'是',sig2是'是',sig3是'不' 。 表示在位置0處,如果sig1是'是'並且sig2是'是'並且sig3是'否'。比它應該返回計數1. –

3

我從你的問題得到了什麼是有物品的數量等於你的字符串可能3只列出你想知道yes其中的數sign1sign2yessign3no

List<string> sign1, sign2, sign3; 
int count = sign1.Where((item, index) => (sign1[index] == 'yes') && 
             (sign2[index] == 'yes') && 
             (sign3[index] == 'no')).Count(); 
+0

thnx fr d幫助,這就是多數民衆贊成在我想.. :) –

0

所以,如果我理解正確的話,你想從列表1得到「是」計數當同一指數在列表2項是「是」,並列出3的相同指標是否定的。

List<string> sig1 = new List<string>(new string[]{"yes","yes","yes"}); 
    List<string> sig2 = new List<string>(new string[] { "yes", "no", "yes" }); 
    List<string> sig3 = new List<string>(new string[] { "no", "yes", "no" }); 

    int count = sig1.Where((s, index) => s == "yes" 
      && sig2.ElementAtOrDefault(index) == "yes" 
      && sig3.ElementAtOrDefault(index) == "no").Count(); 
+0

thnx的幫助...是多數民衆贊成在我想要的.. :) –

相關問題