Search code examples
c#conditional-operator

How to use ternary operator in C#


int number = 5;
  • when the number is equal to 5, write true
  • when the number is not equal to 5, write false

How do I write a statement for this in ASP.NET using C#?


Solution

  • int five = 5;
    string answer = five == 5 ? "true" : "false";
    

    I see that you want to use this to write the values out in ASP.NET, the answer string will hold your desired value, use that as you please.