C#三值输入或在用户输入后都不会输出
我想知道为什么这段代码不输出偶数或奇数,我需要在三元操作之后添加readline语句吗C#三值输入或在用户输入后都不会输出,c#,ternary,C#,Ternary,我想知道为什么这段代码不输出偶数或奇数,我需要在三元操作之后添加readline语句吗 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tenary { class Program { static void Main(string[] args)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace tenary
{
class Program
{
static void Main(string[] args)
{
string input; int a;
Console.WriteLine("Enter a number: ");
input = Console.ReadLine();
a = int.Parse(input);
input = (a % 2 == 0) ? "Even" : "Odd";
Console.ReadLine();
}
}
}
在执行模数检查后,没有任何代码写入控制台
尝试添加
Console.WriteLine(输入)代码>在你的三元组之后你没有输出任何东西,只是在读。添加行:Console.WriteLine(“你的号码是:“+input”);在最后一个控制台之前。ReadLine();没关系,我只是发现代码没有输出任何东西,因为您没有包含输出结果的语句。您只需用三元表达式的结果覆盖输入
。尝试在末尾添加Console.WriteLine(输入)
。