AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
C# Programming
Type of Conversion in which compiler is unable to convert the datatype implicitly is ?
ushort to long
int to uint
byte to decimal
‘int’ is 32 bit signed integer whereas ‘uint’ is 32 bit unsigned integer .Range of int is larger than uint.So,compiler cannot implicitly convert from larger datatype to smaller datatype.
’Implicit Conversion’ follows the order of conversion as per compatibility of datatype as :
float > char > int
char > int > float
int > char > float
float > int > char
Answer: Option B
What is the need for ‘Conversion of data type’ in C#?
To store a value of one data type into a variable of another data type
To get desired data
To prevent situations of run time error during change or conversion of data type
None of the mentioned
Answer: Option (C)
Types of ‘Data Conversion’ in C#?
Implicit Conversion
Explicit Conversion
Implicit Conversion and Explicit Conversion
Answer: Option (B)
Subset of ‘int’ datatype is :
long ,ulong, ushort
long, ulong, uint
long, float, double
long, float, ushort
For the given set of code, is conversion possible?
staticvoid Main(string[] args)
{
int a =76;
char b;
b =(char)a;
Console.WriteLine(b);
Console.ReadLine();
}
Compiler will generate runtime error
Conversion is explicit type
Compiler will urge for conversion from ‘integer’ to ‘character’ datatype
Since, given conversion is of explicit type as one datatype is in integer and other is in ‘char’.Compiler is needed to make a clear distinction between both type of datatypes and hence,explicitly one need to specify datatype as compiler is unable to make automatic conversion. Output : L.
Which of the conversions are valid for the given set of code?
int a =22;
long b =44;
double c =1.406;
b = a;
c= a;
a= b;
b = c;
c = a, b = c
a = b, b = a
b = a, c = a
All of the mentioned
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. Same explanation for option ‘b’. Output : Error 1 :Cannot 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?)
Correct solution :
static void Main(string[] args)
int a = 22;
long b = 44;
double c = 1.406;
c = a;
a = (int)b;
b = (long)c;
For the given set of code select the relevant solution for conversion of data type.
int num1 =20000;
int num2 =50000;
long total;
total = num1 + num2;
Console.WriteLine("Total is : "+total);
Conversion is implicit type, no error generation
Specifying datatype for conversion externally will solve the problem
Since,conversion of datatype is implicit type as ‘int’ is a subset of ‘longtype’ hence no need to explicitly convert data from one type to another.Compiler will automatically do conversion. Output : Total is : 70000.
Predict the relevant output for the given set of code.
float sum;
int i;
sum = 0.0F;
for(i =1; i <=10; i++)
sum = sum +1/(float)i;
Console.WriteLine("sum ="+sum);
2.000
2.910
2.928
3.000
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies