C# banner

C# Multiple Choice Questions (MCQs) and Answers

Master C# with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of C# concepts. Begin your placement preparation journey now!

Q61

Q61 How do you initialize an array with values in C#?

A

int[] arr = {1, 2, 3};

B

int arr = {1, 2, 3};

C

int[] arr = new int[] {1, 2, 3};

D

int arr[] = new int[] {1, 2, 3};

Q62

Q62 How do you declare and initialize a List in C#?

A

List list = new List();

B

List list = List();

C

List list = new List {1, 2, 3};

D

List list = [1, 2, 3];

Q63

Q63 How do you remove an element from a List by index in C#?

A

list.RemoveAt(index);

B

list.Delete(index);

C

list.Remove(index);

D

list.Clear(index);

Q64

Q64 How do you sort a List in C#?

A

list.Sort();

B

list.Order();

C

list.Arrange();

D

list.Align();

Q65

Q65 You get an 'Index out of range' exception.
What is the likely cause?

A

Accessing array element beyond its bounds

B

Incorrect data type

C

Using null value

D

Syntax error

Q66

Q66 You encounter a 'null reference' exception when accessing a collection.
What could be the cause?

A

The collection is not initialized

B

The collection is empty

C

The collection has invalid elements

D

The collection is of incorrect type

Q67

Q67 You get an 'ArgumentOutOfRangeException' when trying to access an element in a List.
What could be the issue?

A

Invalid index value

B

List is not initialized

C

List has no elements

D

Incorrect data type

Q68

Q68 What is a method in C#?

A

A block of code that performs a task

B

A variable

C

A data type

D

An operator

Q69

Q69 Which keyword is used to return a value from a method in C#?

A

break

B

exit

C

return

D

end

Q70

Q70 What is the purpose of the 'static' keyword in a method declaration?

A

Makes the method accessible without an instance

B

Makes the method private

C

Makes the method overrideable

D

None of the above

Q71

Q71 What is an overloaded method in C#?

A

A method with the same name but different parameters

B

A method that returns different types

C

A method that is static

D

A method that is virtual

Q72

Q72 Which of the following is true about method overriding in C#?

A

Overriding requires the 'override' keyword

B

Overriding is the same as overloading

C

Overriding methods must have different names

D

None of the above

Q73

Q73 How do you define a method in C#?

A

void MethodName() { // code }

B

method MethodName() { // code }

C

void MethodName[] { // code }

D

function MethodName() { // code }

Q74

Q74 How do you call a method named 'Display' in C#?

A

Display();

B

call Display();

C

invoke Display();

D

execute Display();

Q75

Q75 How do you define a method that takes an integer parameter in C#?

A

void MethodName(int x) { // code }

B

void MethodName(x int) { // code }

C

void MethodName(int: x) { // code }

D

void MethodName(int) { // code }

Q76

Q76 How do you define a method that returns an integer value in C#?

A

int MethodName() { return 0; }

B

integer MethodName() { return 0; }

C

void MethodName() { return 0; }

D

int MethodName() { }

Q77

Q77 You get a 'missing return statement' error.
What is the likely cause?

A

The method does not return a value

B

The method has no parameters

C

The method is static

D

The method is private

Q78

Q78 You encounter a 'method not found' error.
What could be the cause?

A

Misspelled method name

B

Incorrect method parameters

C

Method is private

D

All of the above

Q79

Q79 What is a class in C#?

A

A blueprint for creating objects

B

A variable

C

A data type

D

A method

Q80

Q80 Which keyword is used to inherit a class in C#?

A

inherit

B

base

C

extends

D

:

Q81

Q81 What is encapsulation in C#?

A

Hiding the implementation details

B

Ability to inherit from another class

C

Writing reusable code

D

All of the above

Q82

Q82 Which of the following supports method overloading in C#?

A

Polymorphism

B

Encapsulation

C

Abstraction

D

Inheritance

Q83

Q83 What is the purpose of the 'virtual' keyword in a method declaration in C#?

A

To allow the method to be overridden in a derived class

B

To make the method static

C

To prevent the method from being overridden

D

None of the above

Q84

Q84 How do you define a class in C#?

A

class MyClass { // code }

B

MyClass class { // code }

C

define class MyClass { // code }

D

class: MyClass { // code }

Q85

Q85 How do you create an object of a class in C#?

A

MyClass obj = new MyClass();

B

MyClass obj();

C

MyClass obj = MyClass();

D

new MyClass obj;

Q86

Q86 How do you define a method in a class that can be overridden in C#?

A

public virtual void MyMethod() { // code }

B

public override void MyMethod() { // code }

C

public void MyMethod() { // code }

D

public static void MyMethod() { // code }

Q87

Q87 You get a 'cannot create an instance of the abstract class' error.
What is the likely cause?

A

Trying to instantiate an abstract class

B

Calling an undefined method

C

Accessing private members

D

Incorrect inheritance

Q88

Q88 You encounter a 'method not overridden' warning.
What could be the issue?

A

The method in the base class is not marked as virtual

B

The method in the derived class is not marked as override

C

The method signatures do not match

D

All of the above

Q89

Q89 You get a 'object reference not set to an instance of an object' error.
What is the most likely cause?

A

Accessing a member of a null object

B

Incorrect method parameters

C

Invalid cast

D

Syntax error

Q90

Q90 What is an object in C#?

A

An instance of a class

B

A blueprint of a class

C

A variable

D

A method

ad verticalad vertical
ad