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.

What will be the output of the following C# code? int a,b; a = (b = 10) + 5;

  1. A. b = 10, a = 5
  2. B. b = 15, a = 5
  3. C. a = 15, b = 10
  4. D. a = 10, b = 10
Report Error

For two strings s1 and s2 to be equal, which is the correct way to find if the contents of two strings are equal?

  1. A. if(s1 = s2)
  2. B. int c; c = s1.CompareTo(s2)
  3. C. if (s1 is s2)
  4. D. if(strcmp(s1, s2))
Report Error

Storage location used by computer memory to store data for usage by an application is?

  1. A. Pointers
  2. B. Constants
  3. C. Variable
  4. D. None of the mentioned
Report Error

For the following C# code select the relevant solution for conversion of data type. static void Main(string[] args) { int num1 = 20000; int num2 = 50000; long total; total = num1 + num2; Console.WriteLine("Total is : " +total); Console.ReadLine(); }

  1. A. Compiler will generate runtime error
  2. B. Conversion is implicit type, no error generation
  3. C. Specifying data type for conversion externally will solve the problem
  4. D. None of the mentioned
Report Error

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

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

Syntax for declaration and initialization of data variable is?

  1. A. =
  2. B.
  3. C.
  4. D. =
Report Error

Choose ".NET class" name from which data type "UInt" is derived?

  1. A. System.Int16
  2. B. System.UInt32
  3. C. System.UInt64
  4. D. System.UInt16
Report Error

Type of Conversion in which compiler is unable to convert the data type implicitly is?

  1. A. ushort to long
  2. B. int to uint
  3. C. byte to decimal
  4. D. None of the above
Report Error

What is the correct way to declare and initialize a string variable in C#?

  1. A. string = str
  2. B. str Hello
  3. C. str = "Hello"
  4. D. string str = "Hello"
Report Error

What is the output of the following code: Console.WriteLine($"5 + 5 = {5 + 5}");

  1. A. 5 + 5 = 10
  2. B. 10
  3. C. $"5 + 5 = {5 + 5}"
  4. D. Compilation error
Report Error

What is the purpose of the 'unchecked' keyword in C#?

  1. A. Enables overflow checking
  2. B. Terminates the program
  3. C. Compiles the program without errors
  4. D. Disables overflow checking for integral-type arithmetic operations
Report Error

What is the correct syntax to declare a nullable integer variable in C#?

  1. A. nullable int num
  2. B. var? num
  3. C. int? num
  4. D. num? int
Report Error