What will be the output of the following C# code? [code] static void Main(string[] args) { double a = 345.09; byte c = (byte) a;

Khánh Đoan

New member
What will be the output of the following C# code?
Code:
static void Main(string[] args)
{
    double a = 345.09;
    byte c = (byte) a;
    Console.WriteLine(c);
    Console.ReadLine();
}
A. 98
B.
Code:
89
C. 88
D. 84
 
Answer: b
Explanation: Type casting a larger variable into a smaller variable results in modules of larger variable by range of smaller variable. a is '345.09' which is larger than byte range ie -128 to 127.
Output :
Code:
89
 

Tìm kiếm

Back
Top