C# 获得“计数”;是”;从我的列表的多个对象<;字符串>;

C# 获得“计数”;是”;从我的列表的多个对象<;字符串>;,c#,C#,我想从列表的多个对象(字符串)中获取“是”的计数。假设我有三个列表sig1,sig2和sig3,它们都包含“yes”或“no”。我想从sig1中得到“是”的计数,其中sig2是“是”,而sig3是“否”。你的问题真的很难理解,但我猜这就是你想要的 List<string> myAnswers = new List<string>() { "yes", "yes", "no" }; Int32 numberOfPositiveAnswers = myAnswers.Coun

我想从列表的多个对象(字符串)中获取“是”的计数。假设我有三个列表
sig1
sig2
sig3
,它们都包含“yes”或“no”。我想从
sig1
中得到“是”的计数,其中
sig2
是“是”,而
sig3
是“否”。

你的问题真的很难理解,但我猜这就是你想要的

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

然后,
numberOfPositiveAnswers
的值将是2。

你的问题真的很难理解,但我猜这就是你想要的

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

然后,
numberOfPositiveAnswers
的值将是2。

我从你的问题中得到的是,你可能有3个具有相同项数的字符串列表,你想知道
yes
的计数,其中
sign1
sign2
yes
,而
sign3
no

List<string> sign1, sign2, sign3;
int count = sign1.Where((item, index) => (sign1[index] == 'yes') &&
                                         (sign2[index] == 'yes') && 
                                         (sign3[index] == 'no')).Count();
列出sign1、sign2、sign3;
int count=sign1。其中((项目,索引)=>(sign1[index]=='yes')&&
(签名2[索引]=“是”)&&
(sign3[index]=“no”).Count();

我从你的问题中得到的是,你可能有3个项目数相等的字符串列表,你想知道
yes
的计数,其中
sign1
sign2
yes
sign3
no

List<string> sign1, sign2, sign3;
int count = sign1.Where((item, index) => (sign1[index] == 'yes') &&
                                         (sign2[index] == 'yes') && 
                                         (sign3[index] == 'no')).Count();
列出sign1、sign2、sign3;
int count=sign1。其中((项目,索引)=>(sign1[index]=='yes')&&
(签名2[索引]=“是”)&&
(sign3[index]=“no”).Count();

因此,如果我理解正确,当列表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();
List sig1=新列表(新字符串[]{“是”、“是”、“是”});
List sig2=新列表(新字符串[]{“是”、“否”、“是”});
List sig3=新列表(新字符串[]{“否”、“是”、“否”});
int count=sig1。其中((s,索引)=>s==“是”
&&sig2.ElementAtOrDefault(索引)=“是”
&&sig3.ElementAtOrDefault(index)=“no”).Count();

因此,如果我理解正确,当列表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();
List sig1=新列表(新字符串[]{“是”、“是”、“是”});
List sig2=新列表(新字符串[]{“是”、“否”、“是”});
List sig3=新列表(新字符串[]{“否”、“是”、“否”});
int count=sig1。其中((s,索引)=>s==“是”
&&sig2.ElementAtOrDefault(索引)=“是”
&&sig3.ElementAtOrDefault(index)=“no”).Count();

sid1、sig2和sig3的结构是什么?到目前为止,您尝试了什么?您需要澄清这一点,很难理解sig2是“是”而sig3是“否”是什么意思?List sig1=new List();List sig2=新列表();List sig3=新列表();下面是三个列表对象,它们只包含数千个“是”和“否”。。。我想要的是sig1的计数,其中它是‘是’,sig2是‘是’,sig3是‘否’。如果sig1为“是”,sig2为“是”,sig3为“否”,则表示位置0。那么它应该返回计数1。为什么不直接使用bool列表呢?sid1、sig2和sig3的结构是什么?到目前为止,您尝试了什么?您需要澄清这一点,很难理解sig2是“是”而sig3是“否”是什么意思?List sig1=new List();List sig2=新列表();List sig3=新列表();下面是三个列表对象,它们只包含数千个“是”和“否”。。。我想要的是sig1的计数,其中它是‘是’,sig2是‘是’,sig3是‘否’。如果sig1为“是”,sig2为“是”,sig3为“否”,则表示位置0。然后返回计数1。为什么不直接使用bool列表呢?List sig1=new List();List sig2=新列表();List sig3=新列表();下面是三个列表对象,它们只包含数千个“是”和“否”。。。我想要的是sig1的计数,其中它是‘是’,sig2是‘是’,sig3是‘否’。如果sig1为“是”,sig2为“是”,sig3为“否”,则表示位置0。然后返回计数1。List sig1=new List();List sig2=新列表();List sig3=新列表();下面是三个列表对象,它们只包含数千个“是”和“否”。。。我想要的是sig1的计数,其中它是‘是’,sig2是‘是’,sig3是‘否’。如果sig1为“是”,sig2为“是”,sig3为“否”,则表示位置0。然后返回count 1.thnx以获取帮助。。。是的,这就是我想要的……)谢谢你的帮助。。。是的,这就是我想要的……)thnx fr d help,yp这就是我想要的……)thnx fr d help,yp这就是我想要的……)