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

Q121

Q121 Which operator is used in LINQ to join two collections based on a related key?

A

Join

B

Union

C

Concat

D

Intersect

Q122

Q122 Which LINQ query syntax in C# retrieves even numbers from a list numbers?

A

from n in numbers where n % 2 == 0 select n;

B

select n where n % 2 == 0 from numbers;

C

where n in numbers select n == 0;

D

select numbers where n % 2 == 0;

Q123

Q123 Which code snippet demonstrates using LINQ’s OrderBy method in C# to sort a list of strings?

A

list.Sort();

B

list.OrderBy();

C

list.OrderBy(x => x);

D

Order(list);

Q124

Q124 How would you perform a group by operation using LINQ to group students by age?

A

students.GroupBy(s => s.Age);

B

students.Select(s => s.Age);

C

students.SortBy(s => s.Age);

D

students.ByGroup(s => s.Age);

Q125

Q125 A "NullReferenceException" occurs during a LINQ query. What could be a likely cause?

A

LINQ syntax error

B

Null variable in query

C

Invalid data type

D

Database connection error

Q126

Q126 A developer notices slow performance when executing a large LINQ query. What could be a potential solution?

A

Avoid OrderBy

B

Optimize query structure

C

Add more conditions

D

Use foreach loop

Q127

Q127 What is Entity Framework primarily used for in .NET?

A

User interface design

B

Database management

C

Data access and ORM

D

Network communication

Q128

Q128 Which approach in Entity Framework generates a database schema based on your code?

A

Database-First

B

Code-First

C

Model-First

D

Query-First

Q129

Q129 What is the purpose of DbContext in Entity Framework?

A

Manages database schema

B

Executes SQL commands

C

Maintains database connection and manages data operations

D

Handles UI

Q130

Q130 Which Entity Framework feature allows developers to track changes in object states?

A

Data Binding

B

Change Tracking

C

Lazy Loading

D

Query Compilation

Q131

Q131 Which method is used to save changes made to the database in Entity Framework?

A

Update()

B

Execute()

C

SaveChanges()

D

ApplyChanges()

Q132

Q132 How would you configure a one-to-many relationship in Entity Framework using the Fluent API?

A

HasOne().WithOne();

B

HasOne().WithMany();

C

HasMany().WithOne();

D

HasMany().WithMany();

Q133

Q133 Which method in Entity Framework is used to execute raw SQL queries and return entity objects?

A

ExecuteRaw()

B

ExecuteQuery()

C

FromSqlRaw()

D

SqlQuery()

Q134

Q134 A "DbUpdateException" occurs when updating data in Entity Framework. What is a likely cause?

A

Foreign key constraint violation

B

Database offline

C

Connection string error

D

Primary key duplication

Q135

Q135 A developer encounters a "LazyInitializationException" in Entity Framework. What could be a solution?

A

Use SaveChanges()

B

Use Include() to load related data

C

Ignore the exception

D

Rewrite query structure

Q136

Q136 What is the purpose of the SecureString class in .NET?

A

To store encrypted strings

B

To securely store sensitive text data in memory

C

To hash passwords

D

To manage secure tokens

Q137

Q137 Which .NET class provides methods for hashing data using algorithms like SHA256?

A

Encryptor

B

HashAlgorithm

C

CryptoStream

D

DataProtector

Q138

Q138 What is the purpose of role-based security in .NET applications?

A

Control access based on user roles

B

Encrypt sensitive data

C

Handle session management

D

Create user profiles

Q139

Q139 Which .NET class is primarily used for asymmetric encryption?

A

Aes

B

Rsa

C

TripleDES

D

Sha256

Q140

Q140 Which code snippet demonstrates encrypting data using Aes encryption in .NET?

A

new Aes().Encrypt(data);

B

Aes.Create().CreateEncryptor();

C

Aes.Encrypt(data);

D

Encrypt(data, Aes);

Q141

Q141 Which method in the CryptoStream class is used to write encrypted data to a stream in .NET?

A

WriteEncrypted()

B

Write()

C

EncryptData()

D

WriteStream()

Q142

Q142 A developer encounters a "CryptographicException" when decrypting data. What could be a likely cause?

A

Incorrect password

B

Key mismatch

C

File is locked

D

Data is too large

Q143

Q143 A "SecureString" cannot be converted directly to a string in .NET. What is the most secure way to handle it?

A

Copy contents to string

B

Store as plain text

C

Use Marshal class to convert securely

D

Read SecureString directly

Q144

Q144 What is the main advantage of .NET Core over the .NET Framework?

A

Better security

B

Cross-platform support

C

Improved UI

D

Easier syntax

Q145

Q145 Which command is used to create a new .NET Core project?

A

dotnet make

B

dotnet new

C

dotnet create

D

dotnet init

Q146

Q146 What is the purpose of the dotnet publish command in .NET Core?

A

To build the application

B

To start the application

C

To create a self-contained deployable package

D

To remove dependencies

Q147

Q147 Which command builds a .NET Core application for production?

A

dotnet release

B

dotnet build -c Release

C

dotnet production

D

dotnet build -r

Q148

Q148 How would you run a .NET Core application from the command line?

A

run dotnet

B

dotnet start

C

dotnet run

D

dotnet execute

Q149

Q149 A "Missing runtime" error occurs when deploying a .NET Core application. What is a likely solution?

A

Reinstall the OS

B

Deploy with dotnet publish

C

Increase memory

D

Use .NET Framework

Q150

Q150 A developer needs to resolve dependency conflicts in a .NET Core project. What tool can assist with this?

A

NuGet

B

MSBuild

C

dotnet clean

D

Dependency Injection

ad verticalad vertical
ad