【问题标题】:Type of conditional expression cannot be determined because there is no implicit conversion between `string' and `int'无法确定条件表达式的类型,因为 `string' 和 `int' 之间没有隐式转换
【发布时间】:2014-08-14 10:26:31
【问题描述】:

我有一个应用程序,它会询问用户一组问题,然后接收这些问题的答案并存储它们。我还有一行有问题的代码,其中控制台返回了有关用户的统计信息。我试图让控制台写出用户回答了多少正确的问题和多少不正确的问题,但是当所说的数量为一时,使“问题”一词成为单数,而当它大于一时,使“问题”一词成为复数。以下是我编写的代码行,虽然我收到标题中写的错误:

Console.WriteLine (
"You have answered {0} question{1} correctly and {2} question{3} incorrectly.",
                correctCount1,
                correctCount1 > 1 || correctCount1 == 0 ? "s" : incorrectCount1,
                incorrectCount1 > 1 || incorrectCount1 == 0 ? "s" :);

【问题讨论】:

  • 我缺少最后一个条件运算符的一部分。那不会编译。

标签: c# string console int


【解决方案1】:

我强烈怀疑:

correctCount1 > 1 || correctCount1 == 0 ? "s" : incorrectCount1

应该是:

correctCount1 > 1 || correctCount1 == 0 ? "s" : "", incorrectCount1

毕竟,你并不真的想让它说:

"You have answered 5 question10"

你呢?

对于最后一个参数也是如此:

incorrectCount1 > 1 || incorrectCount1 == 0 ? "s" :

应该是:

incorrectCount1 > 1 || incorrectCount1 == 0 ? "s" : ""

您总是需要为条件运算符提供三个操作数。

【讨论】:

    猜你喜欢
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 2018-09-27
    • 2016-03-08
    相关资源
    最近更新 更多