List(string) の複数のオブジェクトから「 yes 」の数を取得したい。3 つの listsig1
がsig2
ありsig3
、それらすべてに ' yes ' または ' no ' が含まれているとします。そして、「はい」と「いいえ」から「はい」の数を取得したいと思います。sig1
sig2
sig3
3 に答える
3
私があなたの質問から得たのは、おそらく同じ数のアイテムを持つ文字列の3つのリストがあり、yes
wheresign1
とsign2
isyes
とsign3
isの数を知りたいということですno
。
List<string> sign1, sign2, sign3;
int count = sign1.Where((item, index) => (sign1[index] == 'yes') &&
(sign2[index] == 'yes') &&
(sign3[index] == 'no')).Count();
于 2012-12-22T07:45:00.587 に答える
1
あなたの質問は本当に理解しにくいですが、私はこのようなものがあなたが望むものだと思います。
List<string> myAnswers = new List<string>() { "yes", "yes", "no" };
Int32 numberOfPositiveAnswers = myAnswers.Count(x => x.Equals("yes"));
その場合、の値はnumberOfPositiveAnswers
2になります。
于 2012-12-22T07:39:27.723 に答える
0
したがって、私が正しく理解していれば、リスト2の同じインデックスのアイテムが「はい」で、リスト3の同じインデックスが「いいえ」の場合に、リスト1から「はい」のカウントを取得する必要があります。
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();
于 2012-12-22T07:45:40.967 に答える