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

Q91

Q91 Which class would you use to write data to a binary file in .NET?

A

BinaryReader

B

BinaryWriter

C

FileWriter

D

StreamWriter

Q92

Q92 What does the FileMode.Create option do when opening a file in .NET?

A

Opens file if it exists

B

Throws exception if file exists

C

Creates new file or overwrites existing

D

Creates file only if it doesn’t exist

Q93

Q93 How would you open a file for reading in C#?

A

File.OpenWrite("file.txt")

B

File.OpenRead("file.txt")

C

File.ReadAll("file.txt")

D

File.Open("file.txt")

Q94

Q94 Which code snippet correctly appends text to a file in C#?

A

File.Write("file.txt", "text");

B

File.WriteAll("file.txt", "text");

C

File.AppendAllText("file.txt", "text");

D

File.InsertText("file.txt", "text");

Q95

Q95 How would you delete a file named "oldFile.txt" in C#?

A

File.Remove("oldFile.txt");

B

File.Delete("oldFile.txt");

C

File.Erase("oldFile.txt");

D

File.Unlink("oldFile.txt");

Q96

Q96 A "FileNotFoundException" occurs. What is the likely reason?

A

Incorrect permissions

B

File already open

C

File does not exist

D

File is too large

Q97

Q97 A "UnauthorizedAccessException" occurs while accessing a file. What could be a solution?

A

Check if file is read-only

B

Recompile the program

C

Restart the system

D

Delete the file

Q98

Q98 A developer is unable to read a large file due to memory limitations. What could be a solution?

A

Increase CPU power

B

Use File.ReadAllText

C

Use StreamReader with buffering

D

Close other applications

Q99

Q99 Which language is primarily used for server-side coding in ASP.NET?

A

C++

B

Java

C

C#

D

HTML

Q100

Q100 Which directive is used to include a namespace in an ASP.NET page?

A

#import

B

#include

C

@using

D

@namespace

Q101

Q101 What is the main purpose of ASP.NET Web Forms?

A

To design mobile applications

B

To create Windows applications

C

To develop web applications with a visual interface

D

To handle database connections

Q102

Q102 What is ViewState in ASP.NET?

A

Stores client-side data

B

Stores session data

C

Maintains state of controls

D

Stores cookies

Q103

Q103 Which control in ASP.NET allows data binding with multiple data sources, like SQL databases and XML files?

A

GridView

B

ListView

C

FormView

D

DetailsView

Q104

Q104 How would you create a basic HTML form in an ASP.NET page?

A

<asp:form>

B

<form>

C

<Form>

D

<asp:htmlform>

Q105

Q105 Which code snippet demonstrates how to retrieve a TextBox value in ASP.NET?

A

TextBox1.Value

B

TextBox1.Text

C

TextBox1.Input

D

TextBox1.Data

Q106

Q106 How would you bind a GridView control to a data source programmatically in ASP.NET?

A

GridView.Bind(Data);

B

GridView.DataBind();

C

GridView.DataSource = Data; GridView.DataBind();

D

Bind(GridView, Data);

Q107

Q107 A "NullReferenceException" occurs when accessing a control in ASP.NET. What could be a likely cause?

A

Page not loaded

B

Control is null

C

Invalid variable

D

Form is closed

Q108

Q108 A developer is unable to retain user input after a postback in ASP.NET Web Forms. What might be a solution?

A

Enable ViewState

B

Disable ViewState

C

Clear Session

D

Restart application

Q109

Q109 What is ADO.NET primarily used for in .NET?

A

User interface design

B

Network communication

C

Database access

D

Error handling

Q110

Q110 Which object in ADO.NET is used to establish a connection to a database?

A

DataReader

B

DataAdapter

C

Connection

D

Command

Q111

Q111 What is the purpose of the DataSet in ADO.NET?

A

Fetch a single row

B

Manage database connections

C

Store data locally

D

Execute SQL commands

Q112

Q112 Which of the following is a key advantage of using DataReader over DataSet in ADO.NET?

A

Stores data in memory

B

Supports disconnected data

C

Improved performance for read-only data

D

Easier to update data

Q113

Q113 Which code snippet demonstrates opening a database connection in ADO.NET?

A

connection.Open();

B

connection.Start();

C

connection.Run();

D

connection.Connect();

Q114

Q114 Which ADO.NET class is used to execute a SQL query that returns a single value, such as a count of rows?

A

ExecuteNonQuery

B

ExecuteScalar

C

ExecuteReader

D

ExecuteQuery

Q115

Q115 How would you retrieve data from a DataReader in a while loop in C#?

A

while (reader.Read()) { ... }

B

for (reader.Next()) { ... }

C

if (reader.Fetch()) { ... }

D

loop (reader.Read()) { ... }

Q116

Q116 A "SqlException" is thrown while connecting to a SQL database. What is a likely cause?

A

Incorrect permissions

B

Database is read-only

C

Incorrect connection string

D

Memory overflow

Q117

Q117 A "DataAdapter.Fill" method fails to retrieve data. What could be a potential cause?

A

DataReader closed

B

DataAdapter not initialized

C

Connection not open

D

SQL query missing

Q118

Q118 What does LINQ stand for?

A

Language Integrated Query

B

Logical Integrated Query

C

Library Integrated Query

D

List Integrated Query

Q119

Q119 What is the main advantage of using LINQ in .NET?

A

Improves runtime performance

B

Eliminates need for SQL

C

Type-safe querying

D

Replaces all SQL databases

Q120

Q120 Which LINQ method is used to filter a sequence based on a predicate?

A

Select

B

Where

C

OrderBy

D

Join

ad verticalad vertical
ad