C# (C Sharp) MCQs with answers Page - 20

Here, you will find a collection of MCQ questions on C# (C Sharp). Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833.24K Points
Coach

Q. 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.

  • (A) i
  • (B) i, ii
  • (C) ii
  • (D) None

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

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();
     }
 }
  • (A) 5, 10, 15, 20
  • (B) 0, 5, 10, 20
  • (C) Compile time error
  • (D) 0, 1, 2, 3, 4

A

Admin • 833.24K Points
Coach

Q. Syntax for declaration and initialization of data variable is?

  • (A) <data type><var_name> = <Value>;
  • (B) <data type><var_name>;
  • (C) <var_name><data type>;
  • (D) <var_name> = <value>;

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

Code:
class Program
 {
     public static void Main(string[] args)
     {
         int i, j;
         i = (j = 5) + 10;
         Console. WriteLine(i);
         Console. WriteLine(j);
         Console. ReadLine();
     }
 }
  • (A) 15, 15
  • (B) 10, 5
  • (C) 15, 5
  • (D) 10, 15

A

Admin • 833.24K Points
Coach

Q. Choose effective differences between ‘Boxing’ and ‘Unboxing’.

  • (A) ‘Boxing’ is the process of converting a value type to the reference type and ‘Unboxing’ is the process of converting reference to value type
  • (B) ‘Boxing’ is the process of converting a reference type to value type and ‘Unboxing’ is the process of converting value type to reference type
  • (C) In ‘Boxing’ we need explicit conversion and in ‘Unboxing’ we need implicit conversion
  • (D) Both ‘Boxing’ and ‘Unboxing’ we need implicit conversion

A

Admin • 833.24K Points
Coach

Q. 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

  • (A) i, iii
  • (B) ii, iii
  • (C) i, ii, iii
  • (D) i

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

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();
    }
  • (A) 123, 123
  • (B) 456, 123
  • (C) 456, 456
  • (D) 123, 456

A

Admin • 833.24K Points
Coach

Q. What will be the output of the following C# code?

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();
  }
  • (A) 546, 0
  • (B) 546, 546
  • (C) 546, 70
  • (D) 70, 546

A

Admin • 833.24K Points
Coach

Q. C# is a programming language, developed by ___.

  • (A) Oracle
  • (B) Microsoft
  • (C) GNU project
  • (D) Google

A

Admin • 833.24K Points
Coach

Q. C# runs on the ___.

  • (A) .NET Framework
  • (B) Java Virtual Machine
  • (C) Both A and B.
  • (D) None of the above

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ