What will be the output of the following C# code? [code] static void Main(string[] args) { int a = 5; if (Convert.ToBoolean((.

Tam ca

New member
What will be the output of the following C# code?
Code:
  static void Main(string[] args)
  {  
      int a = 5;
      if (Convert.ToBoolean((.002f) -(0.1f)))
      Console.WriteLine("Sachin Tendulkar");
      else if (a == 5)
      Console.WriteLine("Rahul Dravid");
      else
      Console.WriteLine("Ms Dhoni");
      Console.ReadLine();
  }
A. Rahul Dravid
B.
Code:
 Sachin Tendulkar
C. Ms Dhoni
D. Warning : Unreachable Code
 
Answer: b
Explanation: (0.002 – 0.1f) not equivalent to zero hence it is true. So, only first if clause will execute and print:Sachin Tendulkar on console. As, first condition is always true so no else if statement will be executed.
Output:
Code:
 Sachin Tendulkar
 

Tìm kiếm

Back
Top