C# has a special conditional operator known as ternary operator. This operator compares two values and determines the third value based on the comparison. 

Syntax

Boolean expression ? statement (if true) : statement (in false);

By using ternary operator, you can replace multiple lines if-else statement with a single line of code.

Example

using System;   //Adding namespaces
namespace LearnCSharp //Namespace of the class
{
class Program //The class
{
static void Main(string[] args) //Main method
{
string pass = "";
Console.WriteLine("Enter Password");
pass=Console.ReadLine();
Console.WriteLine(pass == "12345" ? "Welcome admin" : "Invalid Password");
Console.ReadKey();
}
}
}

Output

Enter Password
12345
Welcome admin

Enter Password
123
Invalid Password