1. Choose effective differences between 'Boxing' and 'Unboxing'.
2. Which data type should be more preferred for storing a simple number like 35 to improve execution speed of a program?
3. What will be the output of the following C# code?
public static void Main(string[] args)
{
int i = 123;
object o = i;
i = 456;
System. Console. WriteLine("The value-type value = {0}", i);
System. Console. WriteLine("The object-type value = {0}", o);
Console. ReadLine();
}
public static void Main(string[] args)
{
int i = 123;
object o = i;
i = 456;
System. Console. WriteLine("The value-type value = {0}", i);
System. Console. WriteLine("The object-type value = {0}", o);
Console. ReadLine();
}
4. What will be the output of the following C# code?
class Program
{
static void Main(string[] args)
{
int i ;
for (i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
int i ;
for (i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
5. Number of digits upto which precision value of float data type is valid?
6. Minimum and Maximum range of values supported by 'float' data type are?
7. What will be Correct Set of C# Code for given data 'a' and 'b' to print output for 'c' as 74?
8. What will be the output of the following C# code?
class Program
{
public static void Main(string[] args)
{
int i = 100;
for (a = 0; a < 5; a++)
{
int i = 200;
Console. WriteLine(a * i);
}
Console. ReadLine();
}
}
class Program
{
public static void Main(string[] args)
{
int i = 100;
for (a = 0; a < 5; a++)
{
int i = 200;
Console. WriteLine(a * i);
}
Console. ReadLine();
}
}
9. Given is the code of days(example:"MTWTFSS") which I need to split and hence create a list of days of week in strings( example:"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"). A set of code is given for this purpose but there is the error occurring in that set of code related to the conversion of char to strings. Hence, Select a C# code to solve the given error.
static void Main(string[] args)
{
var days = "MTWTFSS";
var daysArray = days.ToCharArray().Cast<string>().ToArray();
for (var i = 0; i < daysArray.Length; i++)
{
switch (daysArray[i])
{
case "M":
daysArray[i] = "Monday";
break;
case "T":
daysArray[i] = "Tuesday";
break;
case "W":
daysArray[i] = "Wednesday";
break;
case "R":
daysArray[i] = "Thursday";
break;
case "F":
daysArray[i] = "Friday";
break;
case "S":
daysArray[i] = "Saturday";
break;
case "U":
daysArray[i] = "Sunday";
break;
}
}
daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1];
Console.WriteLine(string.Join(", ", daysArray));
}
static void Main(string[] args)
{
var days = "MTWTFSS";
var daysArray = days.ToCharArray().Cast<string>().ToArray();
for (var i = 0; i < daysArray.Length; i++)
{
switch (daysArray[i])
{
case "M":
daysArray[i] = "Monday";
break;
case "T":
daysArray[i] = "Tuesday";
break;
case "W":
daysArray[i] = "Wednesday";
break;
case "R":
daysArray[i] = "Thursday";
break;
case "F":
daysArray[i] = "Friday";
break;
case "S":
daysArray[i] = "Saturday";
break;
case "U":
daysArray[i] = "Sunday";
break;
}
}
daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1];
Console.WriteLine(string.Join(", ", daysArray));
}
10. Does the output remain same or different for both cases?
i.
char l ='k';
float b = 19.0f;
int c;
c = (l / convert.ToInt32(b));
Console.Writeline(c);
ii.
char l ='k';
float b = 19.0f;
int c;
c = Convert.ToInt32(l / b);
console.writeline(c);
i.
char l ='k';
float b = 19.0f;
int c;
c = (l / convert.ToInt32(b));
Console.Writeline(c);
ii.
char l ='k';
float b = 19.0f;
int c;
c = Convert.ToInt32(l / b);
console.writeline(c);
Read More Section(Basic Syntax and Data Types in C Sharp)
Each Section contains maximum 100 MCQs question on Basic Syntax and Data Types in C Sharp. To get more questions visit other sections.