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? static void Main(string[] args) { const int a = 5; const int b = 6; for (int i = 1; i <= 5; i++) { a = a * i; b = b * i; } Console.WriteLine(a); Console.WriteLine(b); Console.ReadLine(); }

  1. A. 600, 720
  2. B. Compile time error
  3. C. 25, 30
  4. D. 5, 6
Report Error

Select differences between reference type and value type: i. Memory allocated to 'Value type' is from heap and reference type is from 'System. ValueType' ii. Memory allocated to 'Value type' is from 'System. ValueType' and reference type is from 'Heap' iii. Structures, enumerated types derived from 'System. ValueType' are created on stack, hence known as ValueType and all 'classes' are reference type because values are stored on heap

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

Which of the conversions are valid for the following C# code? static void Main(string[] args) { int a = 22; long b = 44; double c = 1.406; b = a; c = a; a = b; b = c; }

  1. A. c = a, b = c
  2. B. a = c, b = a
  3. C. b = a, c = a
  4. D. All of the mentioned
Report Error

DIFFERENCE BETWEEN KEYWORDS 'VAR' AND 'DYNAMIC'?

  1. A. 'Var' is introduced in C# (3.0) and 'Dynamic' is introduced in C# (4.0)
  2. B. 'Var' is a type of variable where declaration is done at compile time by compiler while 'Dynamic' declaration is achieved at runtime by compiler
  3. C. For 'Var' Error is caught at compile time and for 'Dynamic' Error is caught at runtime
  4. D. All of the mentioned
Report Error

What will be the output of the following C# code? static void Main(string[] args) { char c = 'g'; string s = c.ToString(); string s1 = "I am a human being" + c; Console.WriteLine(s1); Console.ReadLine(); }

  1. A. I am a human bein c
  2. B. I am a human being
  3. C. I am a human being c
  4. D. I am a human bein
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++) { int j = 0; j += i; Console. WriteLine(j); } Console. WriteLine(i); Console. ReadLine(); } }

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

Scope of variable is related to definition of variable as: i. Region of code within which variable value is valid and hence can be accessed. ii. No, relation with region where variable is declared its value is valid in entire scope.

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

What is the need for 'Conversion of data type' in C#?

  1. A. To store a value of one data type into a variable of another data type
  2. B. To get desired data
  3. C. To prevent situations of runtime error during change or conversion of data type
  4. D. None of the mentioned
Report Error

What will be the output of the following C# code? string s1 = " I AM BEST "; string s2; s2 = s1.substring (5, 4); Console.WriteLine (s2);

  1. A. AM BEST
  2. B. I AM BES
  3. C. BEST
  4. D. I AM
Report Error

The Default value of Boolean Data Type is?

  1. A. 0
  2. B. True
  3. C. False
  4. D. 1
Report Error

Valid Size of float data type is?

  1. A. 10 Bytes
  2. B. 6 Bytes
  3. C. 4 Bytes
  4. D. 8 Bytes
Report Error

The following C# codes are? 1. Myclass class; Myclass class2 = null; 2. int i; int j = 0;

  1. A. True for (1);False for (2)
  2. B. True for (2);False for (1)
  3. C. Both (1) and (2) are equivalents
  4. D. Both (1) and (2) are not equivalents
Report Error