2015-02-12 63 views
-4

我想知道为什么这段代码甚至没有输出或奇数我需要三元操作后添加的readline声明C#三元不会输出要么或用户输入后

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(); 
     } 
    } 
} 
+0

你不outputing什么,只能reading.add行:Console.WriteLine( “您的号码是:” +输入);在最后一个Console.ReadLine()之前; – Fragment 2015-02-12 03:25:34

+0

没关系我只是想通了 – user2005549 2015-02-12 03:25:40

+1

代码不输出任何内容,因为您没有在输出结果的地方包含语句。你只需用你的三元表达式的结果覆盖'input'。尝试在最后添加'Console.WriteLine(输入)'。 – 2015-02-12 03:25:42

回答

0

你不在进行模数检查后,有任何写入控制台的代码。

尝试后加入Console.WriteLine(input);您的三元