理解c#中的语句语法

时间:2015-06-02 13:25:52

标签: c# if-statement

所以我有一个问题要问你们所有人。下面我有一个我最近从这里获得的代码,当我单独留下它时它工作正常,但是一旦我把它放在if语句中,它就不知道如何工作了。

if (apollo.Contains("Savings found"))
{
    int apolloSavings = apollo.Count(line => line.Contains("Savings found:"));
    Console.WriteLine("In Apollo, there were " + apolloSavings + " PNRS);
}

我在想,因为if语句中的代码就像一个循环,它会对if语句进行计数,但我不确定。当您解释问题所在时,请同时说明如何更改该语法以使其在if语句中起作用。

1 个答案:

答案 0 :(得分:0)

没有“找到储蓄”元素。可能有一个包含该字符串的元素。试试if(apollo.Any(item => item.Contains("Savings found")))