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.

Which is the String method used to compare two strings with each other?

  1. A. Compare To()
  2. B. Compare()
  3. C. Copy()
  4. D. ConCat()
Report Error

Choose the correct type of variable scope for the following C# defined variables. class ABC { static int m; int n; void fun (int x , ref int y, out int z, int[] a) { int j = 10; } }

  1. A. m = static variable, n = local variable, x = output parameter, y = reference parameter, j = instance variable, z = output parameter, a[0] = array element
  2. B. m = static variable, n = instance variable, x = value parameter, y = reference parameter, j = local variable, z = output parameter , a[0] = array element
  3. C. m = static variable, n = instance variable, x = reference parameter, y = value parameter, j = local variable, z = output parameter, a[0] = array element
  4. D. m = local variable, n = instance variable, x = reference parameter, y = value parameter, j = static variable, z = output parameter, a[0] = array element
Report Error

What will be the output of the following C# code? static void Main(string[] args) { { var dayCode = "MTWFS"; var daysArray = new List(); var list = new Dictionary { {"M", "Monday"}, {"T", "Tuesday"}, {"W", "Wednesday"}, {"R", "Thursday"}, {"F", "Friday"}, {"S", "Saturday"}, {"U", "Sunday"} }; for (int i = 0,max = dayCode.Length; i < max; i++) { var tmp = dayCode[i].ToString(); if (list.ContainsKey(tmp)) { daysArray.Add(list[tmp]); } } Console.WriteLine(string.Join("n ", daysArray)); }

  1. A. Monday, Tuesday, Wednesday, Friday, Saturday, Sunday
  2. B. Monday Tuesday Wednesday Friday Sunday
  3. C. Monday Tuesday Wednesday Friday Saturday
  4. D. Monday, Tuesday, Wednesday, Friday, Saturday
Report Error

What will be the output of the following C# code? static void Main(string[] args) { string s1 = "Delhi"; string s2; s2 = s1.Insert (6, "Jaipur"); Console.WriteLine(s2); }

  1. A. DelhJaipuri
  2. B. Delhi Jaipur
  3. C. Delhi
  4. D. DelhiJaipur
Report Error

'Implicit Conversion' follows the order of conversion as per compatibility of data type as:

  1. A. float < char < int
  2. B. char < int < float
  3. C. int < char < float
  4. D. float < int < char
Report Error

What will be the output of the following C# code? static void Main(string[] args) { float a = 10.553f; long b = 12L; int c; c = Convert.ToInt32(a + b); Console.WriteLine(c); }

  1. A. 23.453
  2. B. 22
  3. C. 23
  4. D. 22.453
Report Error

What will be the output of the following C# code? public static void Main(string[] args) { int i = 546; object o = i; int n =(int) o; o = 70; System. Console. WriteLine("The value-type value = {0}", n); System. Console. WriteLine("The object-type value = {0}", o); Console. ReadLine(); }

  1. A. 546, 0
  2. B. 546, 546
  3. C. 546, 70
  4. D. 70, 546
Report Error

Correct statement about strings are?

  1. A. a string is created on the stack
  2. B. a string is primitive in nature
  3. C. a string created on heap
  4. D. created of string on a stack or on a heap depends on the length of the string
Report Error

Correct way to assign values to variable 'c' when int a=12, float b=3.5, int c;

  1. A. c = a + b
  2. B. c = a + int(float(b))
  3. C. c = a + convert.ToInt32(b)
  4. D. c = int(a + b)
Report Error

Correct way to define a value 6.28 in a variable 'pi' where value cannot be modified?

  1. A. #define pi 6.28F
  2. B. pi = 6.28F
  3. C. const float pi = 6.28F
  4. D. const float pi pi = 6.28F
Report Error

For the given set of C# code, is conversion possible? static void Main(string[] args) { int a = 76; char b; b = (char)a; Console.WriteLine(b); Console.ReadLine(); }

  1. A. Compiler will generate runtime error
  2. B. Conversion is explicit type
  3. C. Compiler will urge for conversion from 'integer' to 'character' data type
  4. D. None of the mentioned
Report Error

Which Conversion function of 'Convert.TOInt32()' and 'Int32.Parse()' is efficient? i. Int32.Parse() is only used for strings and throws argument exception for null string ii. Convert.Int32() used for data types and returns directly '0' for null string

  1. A. ii
  2. B. Both i, ii
  3. C. i
  4. D. None of the mentioned
Report Error