title: C# conditional operator error Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
body: <p>Hi I was writing a basic program to find if the input number is prime or not. I have a <code>checkPrime(num)</code> function that checks for prime number and returns <code>true</code> if num is prime else returns <code>false</code>. Now in my <code>main()</code> function I used conditional operator to shorten the code but I am getting an error which I am not sure about. Below is my code : </p>
  
  <pre><code>static void Main(String[] args) {
      int n = Int32.Parse(Console.ReadLine());
      while (n-- &gt; 0) {
          int num = Int32.Parse(Console.ReadLine());
          (checkPrime(num) == true) ? Console.WriteLine("Prime") : Console.WriteLine("Not Prime");
      }
  }
  </code></pre>
  
  <p>When I compile, I get the error as <code>Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement</code> in my while loop at conditional statement line. I am not sure what is it that I am missing. There is similar question <a href="https://stackoverflow.com/questions/17820277/only-assignment-call-increment-decrement-await-and-new-object-expressions-c">here</a> and people have answered that the conditional operator line is an expression and not a statement so there has to be some sort or assignment for the value of the expression. Same kind of example is given in <a href="https://msdn.microsoft.com/en-us/library/ty67wk28.aspx" rel="noreferrer">MSDN reference</a> where the explanation does something like this </p>
  
  <pre><code>// ?: conditional operator.
  classify = (input &gt; 0) ? "positive" : "negative";
  </code></pre>
  
  <p>But what I am not able to understand is in my function all I am trying to do is check the return value of the function and then print the output. So where does this expression thing comes in my case. </p>