C# Questions Flashcards

(20 cards)

1
Q

Lifetime of services in .net core

A

scoped transient singleton

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

lazy, explicit and eager loading

A

In .NET Core applications using Entity Framework (EF) Core, eager loading and lazy loading are two strategies for fetching related data from the database. Eager loading retrieves all related data in a single query, while lazy loading defers loading related data until it is explicitly accessed.

Explicit loading is a manual process where you explicitly load related data from the database at a later time, after the main entity has already been retrieved.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what happens when you put a scoped in a singleton

A

Injecting a scoped service into a singleton in .NET Core Dependency Injection (DI) creates a severe issue known as a captive dependency. This problem arises because the scoped service, which is designed to live only for the duration of a single HTTP request, is captured and held by the singleton service, which lives for the entire application lifetime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

compare IEnumerable IQueryable

A

use IQueryable for building efficient database queries, and switch to IEnumerable once the data is in memory and you need to perform client-side operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

explain extension methods

A

allow developers to add new methods to existing classes without modifying their source code. This is widely used in EF Core and LINQ to provide a more readable, fluent syntax for database operations.

Static Class: The extension method must be defined within a static class.
Static Method: The method itself must also be static.
The this Keyword: The first parameter of the method must be preceded by the this keyword, which specifies the type that the method extends.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

explain extension methods in linq

A

Most of the standard LINQ operators, such as Where(), Select(), and Include(), are implemented as extension methods on the IQueryable and IEnumerable interfaces. This is what enables the chaining of methods (e.g., dbContext.Posts.Where(…).Include(…).ToList()) to build complex queries with a clean, readable syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

interfaces

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

di

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

runtask

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

asynch await

A

used to write asynchronous code that looks like synchronous code.
goal is to perform “wait-heavy” operations (like database queries, web requests, or file I/O) without freezing the application’s execution thread.

async Modifier: Marks a method as asynchronous. It tells the compiler that the method can contain await expressions and transforms the method into a state machine behind the scenes.

await Operator: Used inside an async method to pause execution until a specific task is complete. Crucially, it does not block the thread; instead, it yields control back to the caller (like the UI thread) so the application remains responsive while the task runs in the background.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

explain the async await Workflow

A

1 An async method begins executing synchronously like any other method.
2 The Pause: When the code hits an await statement, it checks if the task is already finished. If not, the method suspends and returns a Task (a “promise” of a future result) to the caller.
3 Yielding: While the task runs (e.g., waiting for a server response), the calling thread is free to do other work, such as handling user clicks or processing other requests.
4 Resumption: Once the background task completes, the system “wakes up” the method and resumes execution exactly where it left off.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

explain the async await Standard Syntax and Return Types

A

To use these keywords, your method must return one of the following types:
Task: For an asynchronous operation that doesn’t return a value (similar to void).
Task<T>: For an operation that returns a value of type T.
void: Only used for event handlers (e.g., button clicks), as they cannot be awaited by callers.</T>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

multithread

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

lock

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

dead lock

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

mutex semaphore

17
Q

generics and constraints

18
Q

different ways to use generics in c#

19
Q

Explain serialization and deserialization

A

bits to object

20
Q

explain when to use Dynamic and var

A

var for objects dynamic when object is not defined