Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Which of the conversions are valid for the following C# code?
static void Main(string[] args)
{
int a = 22;
long b = 44;
double c = 1.406;
b = a;
c = a;
a = b;
b = c;
}

Which of the conversions are valid for the following C# code?
static void Main(string[] args)
{
int a = 22;
long b = 44;
double c = 1.406;
b = a;
c = a;
a = b;
b = c;
}
a) c = a, b = c
b) a = c, b = a
c) b = a, c = a
d) All of the mentioned

Answer: a
Explanation: Conversion of data type from ‘int’ to ‘double’ is implicit in nature for ‘c = a’ as int is subset of double but same is not applicable for ‘b = c’ as ‘c’ had wider scope of data range then ‘b’ so explicit conversion is needed.
Output :
Error 1: Can not implicitly convert type ‘long’ to ‘int’. An explicit conversion exists (are you missing a cast?).
Error 2: Cannot implicitly convert type ‘double’ to ‘long’. An explicit conversion exists (are you missing a cast?).

Join The Discussion