csharp Condition Questions & Answers

Question 1: What will be the output of the following program?

public static void Main(string[] args)
{
	int a=5,b=4;
		
	if((a+a)-(a+b)){
	    Console.Write("a>b");
    }
    else
    {
        Console.Write("b>a");
    }
}

Question 2: What will be the output of the following program?

int i = 10, j = 20;

if (i > j)
{
    Console.WriteLine("i is greater than j");
}
else 
{
    Console.WriteLine("i is less than j");
}
else if (i<j) {
    Console.WriteLine("i is equal to j");
}

Question 3: What will be the output of the following program?

int x = 80, y = 60;

var result = x > y ? "x is greater than y" : "x is less than or equal to y";

Console.WriteLine(result);
ADVERTISEMENT

Question 4: What will be the output of the following code?

public static void Main()
{
	int num = 10;
	Type t = num.GetType();

  switch (t) {
    case typeof(int):
      Console.WriteLine("int");
      break;
    case typeof(string):
      Console.WriteLine("string");
      break;
    default:
      Console.WriteLine("unknown");
      break;
  }
}

Question 5: Which of the above statement(s) is true?