C# Condition MCQs

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);

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?

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

public static void Main()
{
	bool x=true, y=false;
		
	if (x) if (y) Func1(); else Func2();
}
	
static void Func1() {
	Console.Write("Func1");
}
	
static void Func2() {
	Console.Write("Func2");
}

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

public static void Main()
{
	int i =1;
	switch (i) {
        case 0:
        while (true) Func1();
    case 1:
        throw new ArgumentException();
    case 2:
        return;
    }
}
	
static void Func1() {
	Console.Write("Func1");
}

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

int a=4, b=6; 
switch (a)
{
    case 4:
        Console.WriteLine ("case 4");
        break;
    case "10":
        Console.WriteLine ("case 10");
        break;
}

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

int a=4, b=6; 
switch (a+b/2)
{
    case 4:
        Console.WriteLine ("case 4");
        break;
    case 5:
        Console.WriteLine ("case 5");
        break;
	case 7:
        Console.WriteLine ("case 7");
        break;
	case 10:
        Console.WriteLine ("case 10");
        break;
}

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

int a=4, b=6; 
switch (a*b)
{
    case a:
        Console.WriteLine ("case a");
        break;
    case a*b:
        Console.WriteLine ("case a*b");
        break;
	case b:
        Console.WriteLine ("case b");
        break;
}