-
Difference between Stored Procedures and Functions:
-
Stored Procedures: Can perform actions such as modifying database tables. They can return multiple values and are called using
EXEC
orCALL
. - Functions: Typically used for computations and return a single value. They can be called from within SQL statements.
-
Stored Procedures: Can perform actions such as modifying database tables. They can return multiple values and are called using
-
Different types of status codes you use for APIs:
- 200 OK: Successful request.
- 201 Created: Resource successfully created.
- 400 Bad Request: Client-side error.
- 401 Unauthorized: Authentication required.
- 403 Forbidden: Server understands the request but refuses to authorize it.
- 404 Not Found: Resource not found.
- 500 Internal Server Error: Server-side error.
-
What status code will you respond with for a successful API request:
- 200 OK for a successful GET request.
- 201 Created for a successful POST request that creates a resource.
-
How do you validate data in API / Different methods to validate data:
- Client-side validation: Using JavaScript or HTML5.
- Server-side validation: Using frameworks like ASP.NET Core.
-
Data annotations: Using attributes like
[Required]
,[StringLength]
, etc. - Custom validation logic: Implementing custom validation methods.
-
Use of Application/Content-Type in API header:
- Specifies the media type of the resource. For example,
application/json
indicates that the content is in JSON format.
- Specifies the media type of the resource. For example,
-
What are the Design patterns you have used, explain:
- Singleton: Ensures a class has only one instance.
- Factory: Creates objects without specifying the exact class.
- Repository: Encapsulates data access logic.
- Dependency Injection: Injects dependencies into a class.
-
How do you secure an API (Authentication / Authorization):
- Authentication: Using OAuth, JWT tokens, or API keys.
- Authorization: Using role-based access control (RBAC) or claims-based authorization.
-
POST vs PUT vs PATCH:
- POST: Creates a new resource.
- PUT: Updates an existing resource or creates it if it doesn't exist.
- PATCH: Partially updates an existing resource.
-
Why should we use PUT over PATCH:
- PUT is idempotent, meaning multiple identical requests will have the same effect as a single request. PATCH is used for partial updates and may not be idempotent.
-
Difference between throw and throw ex:
- throw: Preserves the original stack trace.
- throw ex: Resets the stack trace, making it harder to debug.
-
Can you implement multiple interfaces with the same method signatures in C#:
- Yes, you can implement multiple interfaces with the same method signatures. You may need to use explicit interface implementation to avoid ambiguity.
-
How do you make sure the data streaming via event hubs are consistent. How to tackle the failed events/data:
- Use checkpointing to track the progress of event processing.
- Implement retry logic for failed events.
- Use dead-letter queues to handle events that cannot be processed.
-
How do you make sure you follow SOLID principles in your development:
- Single Responsibility Principle: Each class should have only one reason to change.
- Open/Closed Principle: Classes should be open for extension but closed for modification.
- Liskov Substitution Principle: Subtypes must be substitutable for their base types.
- Interface Segregation Principle: Clients should not be forced to depend on interfaces they do not use.
- Dependency Inversion Principle: Depend on abstractions, not concretions.
-
What are the steps to write unit (TDD) testing for a controller:
- Write a failing test.
- Write the minimum code to pass the test.
- Refactor the code while ensuring the test passes.
- Repeat the process.
-
Stack vs Heap:
- Stack: Stores value types and method call information. Memory allocation is fast and managed by the system.
- Heap: Stores reference types. Memory allocation is slower and managed by the garbage collector.
- Example:
int x = 10; // Stored in stack Person person = new Person(); // Stored in heap
-
Strongly typed vs Weakly typed:
- Strongly typed: Variables are bound to a specific data type.
- Weakly typed: Variables can hold any data type.
- Example:
// Strongly typed int number = 10; string text = "Hello"; // Weakly typed (using dynamic) dynamic value = 10; value = "Hello";
-
Advantages of dependency injections:
- Promotes loose coupling.
- Enhances testability.
- Improves maintainability.
-
Transient, Scoped vs Singleton:
- Transient: A new instance is created each time it is requested.
- Scoped: A single instance is created per request.
- Singleton: A single instance is created and shared throughout the application's lifetime.
-
Difference between PUT and PATCH with practical example:
- PUT: Replaces the entire resource.
- PATCH: Updates part of the resource.
- Example:
// PUT request { "name": "John", "age": 30 } // PATCH request { "age": 31 }
-
Implementing multiple interfaces with the same method signatures in C#:
- Example:
interface IFirst { void Method(); } interface ISecond { void Method(); } class MyClass : IFirst, ISecond { void IFirst.Method() { Console.WriteLine("IFirst Method"); } void ISecond.Method() { Console.WriteLine("ISecond Method"); } }
-
Explain the difference between synchronous and asynchronous programming:
- Synchronous: Code execution waits for each operation to complete before moving to the next one.
- Asynchronous: Code execution continues without waiting for the operation to complete, allowing other operations to run concurrently.
- Example:
// Synchronous public void SyncMethod() { var result = LongRunningOperation(); Console.WriteLine(result); } // Asynchronous public async Task AsyncMethod() { var result = await LongRunningOperationAsync(); Console.WriteLine(result); }
-
What is the difference between an abstract class and an interface in C#:
- Abstract Class: Can have implementations for some of its members. Cannot be instantiated.
- Interface: Cannot have implementations for any of its members. Defines a contract that implementing classes must follow.
- Example:
// Abstract Class public abstract class Animal { public abstract void MakeSound(); public void Sleep() { Console.WriteLine("Sleeping"); } } // Interface public interface IAnimal { void MakeSound(); }
-
Explain the concept of garbage collection in .NET:
- Garbage Collection: Automatic memory management feature that reclaims memory occupied by objects that are no longer in use.
- Generations: Objects are categorized into generations (0, 1, 2) to optimize the garbage collection process.
-
What is the purpose of the
async
andawait
keywords in C#:-
async
: Marks a method as asynchronous. -
await
: Pauses the execution of the method until the awaited task completes. - Example:
public async Task<string> GetDataAsync() { await Task.Delay(1000); // Simulate a delay return "Data"; }
-
-
Explain the difference between
IEnumerable
andIQueryable
:-
IEnumerable
: Used for in-memory collections. Executes queries on the server side. -
IQueryable
: Used for querying data from a database. Executes queries on the client side.
-
-
What is the purpose of the
using
statement in C#:- Ensures that resources are disposed of properly.
- Example:
using (var stream = new FileStream("file.txt", FileMode.Open)) { // Use the stream } // Stream is disposed of here
-
Explain the concept of dependency injection:
- Design pattern that allows the creation of dependent objects outside of a class and provides those objects to the class.
- Example:
public class MyService { private readonly IMyDependency _dependency; public MyService(IMyDependency dependency) { _dependency = dependency; } }
-
What is the difference between
Task
andThread
in C#:-
Task
: Represents an asynchronous operation. Higher-level abstraction. -
Thread
: Represents a thread of execution. Lower-level abstraction.
-
-
Explain the concept of middleware in ASP.NET Core:
- Middleware are components that are assembled into an application pipeline to handle requests and responses.
- Example:
public void Configure(IApplicationBuilder app) { app.Use(async (context, next) => { // Do something before the next middleware await next.Invoke(); // Do something after the next middleware }); }
-
What is the purpose of the
ConfigureServices
method in ASP.NET Core:- Used to configure the application's services and dependency injection container.
- Example:
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddDbContext<MyDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); }
-
Explain the concept of event-driven programming:
- Programming paradigm where the flow of the program is determined by events such as user actions, sensor outputs, or message passing.
- Example:
public class Button { public event EventHandler Click; protected virtual void OnClick(EventArgs e) { Click?.Invoke(this, e); } }
-
What is the purpose of the
Configure
method in ASP.NET Core:- Used to configure the application's request pipeline.
- Example:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); }
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)