Commerce

Basic Syntax And Data Types In C Sharp MCQs

Practice Basic Syntax And Data Types In C Sharp MCQs for competitive exams.

Basic Syntax And Data Types In C Sharp MCQs

Practice questions from this topic.

Select appropriate difference between decimal, float and double data type in C#? i. Float and Double are floating binary point types while decimal is a floating decimal point type. ii. Precision difference for float is '7' digit for double is '15' to '16' digit and for decimal is '28' to '29' digits. iii. Some values which cannot be exactly represented hence for those values float and double are more appropriate.

  1. A. i
  2. B. i, iii
  3. C. i, ii, iii
  4. D. ii, iii
Report Error

What will be the output of the following C# code? public static void Main(string[] args) { double ZERO = 0; Console.WriteLine("RESULT OF DIVISION BY ZERO IS :{0}", (0 / ZERO)); Console.ReadLine(); }

  1. A. 1
  2. B. exception argument is thrown
  3. C. NaN
  4. D. 0
Report Error

Arrange the following data type in order of increasing magnitude sbyte, short, long, int.

  1. A. long < short < int < sbyte
  2. B. sbyte < short < int < long
  3. C. short < sbyte < int < long
  4. D. short < int < sbyte < long
Report Error

Select the correct differences between char and varchar data types? i. varchar is non unicode and char is unicode character data type ii. char is 'n' bytes whereas varchar is actual length in bytes of data entered in terms of storage size iii. varchar is variable in length and char is the fixed length string iv. For varchar, if a string is less than the maximum length then it is stored in verbatim without any extra characters while for char if a string is less than the set length it is padded with extra characters to equalize its length to given length

  1. A. i, iii, iv
  2. B. ii, iii, iv
  3. C. i, ii, iv
  4. D. iii, iv
Report Error

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);

  1. A. Yes
  2. B. No
Report Error

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().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)); }

  1. A. var daysArray = new List()
  2. B. var daysArray = days.Select(c =>dayMapping[c]).ToArray()
  3. C. var daysArray = days.ToCharArray().Select(c =>c.Tostring()).ToArray()
  4. D. var daysArray = days.Select()
Report Error

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(); } }

  1. A. 5, 10, 15, 20
  2. B. 0, 5, 10, 20
  3. C. Compile time error
  4. D. 0, 1, 2, 3, 4
Report Error

What will be Correct Set of C# Code for given data 'a' and 'b' to print output for 'c' as 74?

  1. A. int a = 12; float b = 6.2f; int c; c = a / b + a * b; Console.WriteLine(c)
  2. B. int a = 12; float b = 6.2f; int c; c = a / convert.ToInt32(b) + a * b; Console.WriteLine(c)
  3. C. int a = 12; float b = 6.2f; int c; c = a / convert.ToInt32(b) + a * convert.ToInt32(b); Console.WriteLine(c)
  4. D. int a = 12; float b = 6.2f; int c; c = convert.ToInt32(a / b + a * b); Console.WriteLine(c)
Report Error

Minimum and Maximum range of values supported by 'float' data type are?

  1. A. 1.5 * 10 -40 to 3.4 * 10 38
  2. B. 1.5 * 10 -45 to 3.4 * 10 30
  3. C. 1.5 * 10 -45 to 3.4 * 10 38
  4. D. 1.5 * 10 -45 to 3.4 * 10 37
Report Error

Number of digits upto which precision value of float data type is valid?

  1. A. Upto 6 digit
  2. B. Upto 8 digit
  3. C. Upto 9 digit
  4. D. Upto 7 digit
Report Error

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(); }

  1. A. 123, 123
  2. B. 456, 123
  3. C. 456, 456
  4. D. 123, 456
Report Error

Which data type should be more preferred for storing a simple number like 35 to improve execution speed of a program?

  1. A. sbyte
  2. B. short
  3. C. int
  4. D. long
Report Error