.net banner

.NET Multiple Choice Questions (MCQs) and Answers

Master .NET 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 .NET concepts. Begin your placement preparation journey now!

Q61

Q61 Which exception is caught by the catch (Exception ex) statement?

A

Only Exception

B

All exceptions derived from Exception

C

System-level errors

D

Only runtime errors

Q62

Q62 How do you rethrow an exception in C# without resetting the stack trace?

A

throw;

B

throw ex;

C

throw new Exception(ex);

D

rethrow ex;

Q63

Q63 A "NullReferenceException" occurs. What is the most likely reason?

A

Object is null

B

File not found

C

Syntax error

D

Array index out of bounds

Q64

Q64 An application frequently throws an OutOfMemoryException. What could be a solution?

A

Increase system memory

B

Optimize memory usage

C

Use more variables

D

Reduce CPU usage

Q65

Q65 A developer wants to log details of an exception without disrupting execution. What is a possible approach?

A

Use throw;

B

Log in catch block and continue

C

Avoid catch block

D

Use finally block

Q66

Q66 Which concept of OOP allows the creation of objects from a class?

A

Inheritance

B

Encapsulation

C

Polymorphism

D

Instantiation

Q67

Q67 What is encapsulation in OOP?

A

Combining methods and properties

B

Hiding data

C

Allowing multiple forms

D

Creating objects

Q68

Q68 Which OOP feature allows a derived class to inherit properties from a base class?

A

Abstraction

B

Polymorphism

C

Inheritance

D

Encapsulation

Q69

Q69 Which keyword is used in C# to prevent a class from being inherited?

A

sealed

B

static

C

readonly

D

protected

Q70

Q70 What is the purpose of polymorphism in OOP?

A

To hide data

B

To enhance readability

C

To enable objects to take many forms

D

To provide inheritance

Q71

Q71 How would you declare a simple class named Person in C#?

A

class Person { }

B

Person class { }

C

object Person { }

D

struct Person { }

Q72

Q72 Which C# keyword is used to call a base class constructor from a derived class?

A

this

B

super

C

base

D

inherit

Q73

Q73 Which code snippet correctly demonstrates method overriding in C#?

A

override void Print()

B

override method Print()

C

override class Print()

D

new method Print()

Q74

Q74 How would you declare an abstract method named Calculate in an abstract class?

A

abstract void Calculate();

B

abstract Calculate();

C

void abstract Calculate();

D

Calculate abstract void();

Q75

Q75 A developer encounters an error saying "Object reference not set to an instance of an object." What is likely the cause?

A

The object is null

B

The object has been disposed

C

Data type mismatch

D

Method does not exist

Q76

Q76 A method is not accessible outside its class, even when the instance is created. What could be the reason?

A

The method is public

B

The method is private

C

The method is static

D

The method is sealed

Q77

Q77 A derived class cannot inherit members of a base class. What might be the cause?

A

Members are sealed

B

Members are internal

C

Members are protected

D

Members are abstract

Q78

Q78 Which of the following is a generic collection in .NET?

A

Array

B

List

C

Hashtable

D

ArrayList

Q79

Q79 What is the primary benefit of using generics in .NET?

A

Reduces memory usage

B

Improves code readability

C

Increases type safety

D

Improves debugging

Q80

Q80 Which namespace provides collection classes like List and Dictionary<K, V>?

A

System

B

System.Generic

C

System.Collections.Generic

D

System.Data

Q81

Q81 Which interface is implemented by collections that can be iterated in a foreach loop?

A

IEnumerable

B

IEnumerator

C

IList

D

ICollection

Q82

Q82 What is the difference between Dictionary<K, V> and Hashtable in .NET?

A

Both are type-safe

B

Hashtable is generic

C

Dictionary is type-safe

D

Hashtable is faster

Q83

Q83 How would you declare a generic List of integers in C#?

A

List numbers = new List();

B

List numbers = new List();

C

List numbers = new List();

D

List = numbers;

Q84

Q84 Which code snippet demonstrates adding a key-value pair to a Dictionary<string, int> in C#?

A

dict.Add("one", 1);

B

dict.Insert("one", 1);

C

dict["one"] = 1;

D

dict.put("one", 1);

Q85

Q85 How do you remove an item with a specific key from a Dictionary<int, string> in C#?

A

dict.Delete(1);

B

dict.Remove(1);

C

dict.Clear(1);

D

dict.Erase(1);

Q86

Q86 A KeyNotFoundException occurs when accessing a dictionary. What is likely the cause?

A

The key is missing

B

The value is null

C

The dictionary is empty

D

The key is duplicated

Q87

Q87 An InvalidOperationException occurs when modifying a collection during iteration. What is a possible solution?

A

Use a for loop

B

Use a foreach loop

C

Use a sorted collection

D

Clear the collection first

Q88

Q88 A developer wants to prevent duplicate keys in a collection. Which collection should they use?

A

List

B

Hashtable

C

Dictionary

D

SortedSet

Q89

Q89 Which namespace provides classes for file handling in .NET?

A

System.Data

B

System.IO

C

System.File

D

System.Text

Q90

Q90 Which class in .NET is used to read text from a file?

A

TextReader

B

StreamReader

C

FileReader

D

TextWriter

ad verticalad vertical
ad