DEV Community

Cover image for Must to know .net / .net core interview Questions for developers
yogini16
yogini16

Posted on

Must to know .net / .net core interview Questions for developers

Here are few interview questions, though now .net core is so popular, few questions might feel as outdated, but it's nice to know about the tech.

1. What is .NET?

.NET is a software development framework developed by Microsoft. It provides a set of libraries and runtime environments to build and run various types of applications, including web, desktop, and mobile applications.

2. Explain the Common Language Runtime (CLR).

CLR is the heart of the .NET framework. It manages memory, enforces security, and handles exception handling. It also provides features like Just-In-Time (JIT) compilation, which converts Intermediate Language (IL) code into native machine code for execution.

3. What is the difference between C# and VB.NET?

C# and VB.NET are both .NET languages. The main difference is in syntax and coding style. C# uses a C-style syntax, while VB.NET uses a more verbose syntax. However, both can achieve the same functionality and have access to the same .NET framework libraries.

4. Explain the garbage collection process in .NET.

Garbage collection is the automatic process of deallocating memory occupied by objects that are no longer in use. The CLR uses various algorithms to identify and reclaim memory. Developers don't need to explicitly manage memory, as the garbage collector takes care of it.

5. What is an assembly in .NET?

An assembly is a fundamental unit of deployment in .NET. It can be a DLL (Dynamic Link Library) or an EXE (Executable) file that contains compiled code, metadata, and resources. Assemblies can be shared among multiple applications.

6. What are the different types of assemblies in .NET?

There are two main types of assemblies in .NET:

Private Assemblies: These are used for single applications and are stored in the application's directory.
Shared Assemblies: These are stored in the Global Assembly Cache (GAC) and can be accessed by multiple applications.

7. What is the Global Assembly Cache (GAC)?

The GAC is a central repository for shared .NET assemblies. It allows multiple applications to share and use the same version of an assembly, ensuring versioning and strong-naming of assemblies.

8. Explain the concept of inheritance in C#.

Inheritance is a mechanism in C# where a new class (derived or child class) is created by inheriting properties and behaviors from an existing class (base or parent class). It promotes code reusability and the creation of a hierarchy of classes.

9. What is the difference between value types and reference types in C#?

Value Types: Value types store their actual data value directly. They include primitive types like int, float, and structs. They are stored on the stack.
Reference Types: Reference types store references to their data. They include classes, interfaces, and delegates. They are stored on the heap.

10. What is ASP.NET and how does it differ from ASP.NET Core?

ASP.NET is a web development framework for building web applications. ASP.NET Core is a newer, cross-platform framework that is a complete rewrite of ASP.NET. ASP.NET Core is more lightweight, modular, and can run on Windows, Linux, and macOS.

11. Explain the use of the "using" statement in C# and its significance.

The "using" statement is used for resource management, particularly with objects that implement the IDisposable interface. It ensures that the object's Dispose method is called when it goes out of scope, thus releasing resources like file handles or database connections.

12. What is Entity Framework (EF) in .NET?

Entity Framework is an Object-Relational Mapping (ORM) framework provided by Microsoft. It simplifies database interactions by allowing developers to work with databases using .NET objects and LINQ queries, abstracting the underlying SQL.

13. What is the difference between an abstract class and an interface in C#?

Abstract Class: An abstract class can have both abstract (unimplemented) and concrete (implemented) methods. It can also have fields and constructors. A class can inherit from only one abstract class.

Interface: An interface can only contain method signatures (declarations), properties, events, and indexers. A class can implement multiple interfaces.

14. What are delegates in C#?

Delegates are a type-safe function pointer that allows you to reference methods and treat them as objects. They are often used for implementing events and callback mechanisms.

15. Explain the purpose of the 'async' and 'await' keywords in C#.

The 'async' keyword is used to mark a method as asynchronous, allowing it to run asynchronously. The 'await' keyword is used inside an async method to await the completion of an asynchronous operation without blocking the calling thread.

16. What is Dependency Injection in .NET?

Dependency Injection (DI) is a design pattern used to achieve loose coupling between components in an application. It allows objects to receive their dependencies from an external source (usually a container) rather than creating them internally.

17. What is the role of the App.config or Web.config file in .NET applications?

These configuration files store application-specific settings such as connection strings, application settings, and custom configurations. They can be easily modified without recompiling the application, promoting flexibility and maintainability.

18. Explain the purpose of the 'using' directive in C# and how it differs from the 'using' statement.

The 'using' directive is used to include namespaces in your code, making types within those namespaces accessible. It doesn't have the same purpose as the 'using' statement used for resource management. The 'using' statement ensures proper disposal of resources, as discussed in question 11.

19. What is the difference between the 'StringBuilder' and 'String' classes in .NET?

StringBuilder: StringBuilder is used for dynamic string manipulation. It allows you to efficiently concatenate, modify, or build strings without creating new string objects, which can be more memory and performance efficient.

String: The String class represents an immutable string object, which means once a string is created, it cannot be changed. Any operation that appears to modify a string results in the creation of a new string.

20. What is ASP.NET MVC, and how does it differ from ASP.NET Web Forms?

ASP.NET MVC is a web application framework that promotes the Model-View-Controller architectural pattern. It offers more control over HTML markup and allows for easier testability. ASP.NET Web Forms, on the other hand, uses a different event-driven model and is often considered less flexible for modern web development.

21. What is the purpose of the 'finally' block in exception handling in C#?

The 'finally' block is used to specify code that should be executed regardless of whether an exception is thrown or not. It is typically used for cleanup tasks like closing files, releasing resources, or ensuring specific actions are taken after a try-catch block.

22. Explain the concept of authentication and authorization in ASP.NET.

Authentication: Authentication verifies the identity of a user, ensuring they are who they claim to be. ASP.NET supports various authentication methods, including forms-based authentication, Windows authentication, and third-party authentication providers like OAuth.

Authorization: Authorization determines what actions a user is allowed to perform once they are authenticated. It specifies access control rules and permissions for different parts of a web application.

23. What is .NET Core, and how does it differ from the traditional .NET Framework?

.NET Core: .NET Core is a cross-platform, open-source framework for building modern, high-performance applications. It's designed to be lightweight, modular, and suitable for a wide range of applications, including web, mobile, cloud, and IoT.

Differences: .NET Core is cross-platform (runs on Windows, Linux, macOS), supports containerization, and offers improved performance. It's designed for modern development scenarios and is not backward compatible with the full .NET Framework.

24. Explain the concept of Dependency Injection in .NET Core.

Dependency Injection in .NET Core is a technique for achieving loose coupling between components by injecting dependencies into a class rather than creating them internally. It's a core principle in building maintainable, testable, and modular applications.

25. What is Kestrel in the context of ASP.NET Core?

Kestrel is a cross-platform web server built for ASP.NET Core. It's a lightweight, high-performance server optimized for serving web applications. Kestrel can be used as a standalone server or in combination with a reverse proxy like IIS or Nginx.

26. Explain Middleware in ASP.NET Core.

Middleware in ASP.NET Core is a component that sits in the request-response pipeline. It can handle requests, modify responses, or perform various tasks such as authentication, logging, error handling, and more. Middleware is added to the pipeline in a specific order and can be custom or built-in.

27. What is the purpose of the Startup.cs file in an ASP.NET Core application?

The Startup.cs file is a key part of ASP.NET Core applications. It contains the configuration code for the application, including middleware setup, dependency injection configuration, and the definition of services. It's where you define how the application behaves at startup.

28. Explain the concept of Tag Helpers in ASP.NET Core.

Tag Helpers in ASP.NET Core are a feature that allows developers to create custom HTML-like tags that are processed on the server side. They simplify working with HTML in Razor views and provide a more natural syntax for incorporating server-side logic.

29. What is ASP.NET Core MVC and how does it differ from traditional ASP.NET MVC?

ASP.NET Core MVC: ASP.NET Core MVC is a lightweight, high-performance framework for building web applications using the Model-View-Controller pattern. It's part of the .NET Core ecosystem and is cross-platform.

Differences: ASP.NET Core MVC is designed to work with .NET Core and is more modular and lightweight compared to traditional ASP.NET MVC. It's optimized for modern web development and provides better support for features like dependency injection.

30. What is Entity Framework Core (EF Core)?

Entity Framework Core (EF Core) is an Object-Relational Mapping (ORM) framework provided by Microsoft for .NET Core applications. It allows developers to work with databases using .NET objects and LINQ queries, abstracting the underlying SQL.

31. What is Razor Pages in ASP.NET Core?

Razor Pages is a page-based programming model in ASP.NET Core. It combines the view and controller logic into a single file, making it more straightforward for developers to build web applications with less ceremony compared to traditional MVC.

32. Explain the purpose of the appsettings.json file in ASP.NET Core.

The appsettings.json file is used to store configuration settings for an ASP.NET Core application. It allows developers to separate configuration from code, making it easier to change settings without recompiling the application. It's commonly used for storing connection strings, API keys, and other application-specific settings.

33. What is state management in web applications, and why is it important?

State management refers to the process of preserving data between multiple requests in a web application. It's crucial because HTTP is a stateless protocol, meaning that each request/response cycle doesn't inherently maintain any information about previous interactions. State management enables the persistence of user data and session information across requests.

34. What are the different types of state management techniques in ASP.NET?

There are several state management techniques in ASP.NET, including:

View State: Stores data on the client side in a hidden field. It's primarily used for maintaining control state.

Session State: Stores data on the server side, associated with a user's session. It's useful for preserving user-specific data during a session.

Application State: Stores data that is shared among all users of an application. It's useful for storing global configuration settings.

Cookies: Stores small amounts of data on the client side. It's often used for maintaining user preferences or tracking user behavior.

Query Strings: Appends data to the URL, making it accessible on subsequent requests. It's suitable for passing data between pages.

35. Explain the differences between ViewState and Session State in ASP.NET.

ViewState: ViewState is used to store control-specific data on the client side, typically within an HTML hidden field. It preserves control state across postbacks and is limited to a single page.

Session State: Session State stores data on the server side and is associated with a user's session. It can persist data across multiple pages within the same session, making it suitable for user-specific data.

36. What are the advantages and disadvantages of using cookies for state management?

Advantages:
Cookies are easy to implement and use.
They can persist data across multiple sessions.
They work well for storing small amounts of data.

Disadvantages:
Cookies have a limited size (typically 4KB per cookie).
Security concerns: Cookies can be tampered with, and sensitive data should not be stored in cookies.
Some users may disable cookies in their browsers.

37. How does the TempData object work in ASP.NET Core?
TempData is a dictionary-like object in ASP.NET Core used to store data that should be available for the duration of a single HTTP request. It is often used for passing data between actions when performing redirects. TempData values are stored in the session and automatically removed after they are read.

38. What is the role of the "Application_Start" event in ASP.NET's Global.asax file?

The "Application_Start" event in Global.asax is fired when the ASP.NET application starts or is first accessed. It's typically used to perform application-level initialization tasks, such as configuring global settings or setting up application-wide resources. This event is executed only once when the application starts.

39. Explain the concept of "Client-Side State Management."

Client-side state management involves storing and managing data directly on the client's device (usually in the browser). This can include using technologies like cookies, Web Storage (localStorage and sessionStorage), and client-side frameworks (e.g., React or Angular) to manage state without relying heavily on server-side resources. It can enhance performance and reduce server load but should be used carefully to ensure data integrity and security.

40. What are the security considerations when managing state in web applications?

Avoid storing sensitive data on the client side.
Use encryption when transmitting state data.
Validate and sanitize data received from the client to prevent injection attacks.

41. What is a JSON Web Token (JWT)?

A JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties. It is digitally signed, ensuring that the claims contained in the token are trustworthy.

42. Explain the structure of a JWT.

A JWT is comprised of three parts, separated by dots:

Header: Contains information about the type of token and the signing algorithm used.
Payload: Contains claims (data) in the form of key-value pairs. These can be custom claims or predefined ones like "iss" (issuer), "exp" (expiration time), and "sub" (subject).
Signature: Created by encoding the header, payload, and a secret key with the specified algorithm. It ensures that the token hasn't been tampered with.
The three parts are base64Url encoded and joined with periods (header.payload.signature).

43. How is a JWT validated?

JWT validation involves verifying the signature to ensure the token hasn't been tampered with. This is done by:

Decoding the JWT to extract the header and payload.
Using the same algorithm and secret key that was used to sign the JWT to recompute the signature.
Comparing the computed signature with the one in the JWT. If they match, the token is considered valid.

44. What is the purpose of the "Issuer" claim in a JWT?

The "iss" claim in a JWT identifies the entity that issued the token. It provides information about the authority or system that generated the token. This can be useful in scenarios where different authorities issue tokens, and you want to verify the source of the token.

45. Explain the "Expiration Time" claim ("exp") in a JWT.

The "exp" claim indicates the timestamp (in seconds since the Unix epoch) at which the token will expire. After this time, the token should not be considered valid, and the recipient should request a new token.

46. What is the significance of the "Subject" claim ("sub") in a JWT?

The "sub" claim in a JWT identifies the subject of the token. It typically represents the entity (e.g., user or system) that the token is about. This claim is often used to associate a token with a specific user or resource.

47. How do JWTs improve security in web applications?

Stateless: JWTs are self-contained and contain all necessary information. This reduces the need for server-side storage of session data.
Tamper-Resistant: The signature ensures that the token hasn't been altered. If the signature doesn't match, the token is considered invalid.
Encrypted Payloads: While not a standard feature, JWTs can be encrypted to protect sensitive information.

48. What are some common use cases for JWTs?

Authentication: JWTs are commonly used for user authentication. After logging in, the server generates a JWT which is then sent to the client. The client includes the token in subsequent requests to access protected resources.
Information Exchange: JWTs are used to securely exchange information between parties in a compact and standardized format.
Single Sign-On (SSO): JWTs are often used in SSO systems to facilitate seamless authentication across multiple services or applications.

49. What is caching, and why is it important in software development?

Caching is the process of storing frequently used data in a high-speed, easily accessible storage layer (cache) to reduce the need to fetch the data from a slower or more distant source. Caching is important because it can significantly improve application performance by reducing latency and server load.

50. Explain the difference between client-side caching and server-side caching.

Client-Side Caching: This involves storing data on the client device (e.g., in the browser) to avoid unnecessary requests to the server. Examples include browser caching of static assets like images and CSS files.

Server-Side Caching: This involves storing data on the server or in an intermediate layer (like a caching server or database cache). It reduces the load on the server by serving frequently requested data more quickly.

51. What are the common caching strategies used in web applications?

Common caching strategies include:

Page Caching: Storing the entire HTML output of a page to serve it quickly to subsequent users without re-generating the page.

Object Caching: Storing specific data objects, such as database query results, in memory for faster retrieval.

Output Caching: Caching the output of specific methods or API calls to avoid redundant processing.

52. Explain the concept of "Cache Invalidation" and its importance.

Cache Invalidation is the process of removing or updating cached data when it becomes stale or outdated. It's crucial to ensure that users receive up-to-date information. Cache Invalidation can be done based on time-to-live (TTL), events, or changes to the underlying data source.

53. What is a cache eviction policy, and what are some common eviction policies?

A cache eviction policy determines which items are removed from the cache when it becomes full or when cache items expire. Common eviction policies include:

Least Recently Used (LRU): Removes the least recently accessed items first.

Least Frequently Used (LFU): Removes the least frequently accessed items first.

Time-to-Live (TTL): Removes items that have exceeded their specified time-to-live.

54. Explain the concept of "Cache-Aside" caching and "Write-Through" caching.

Cache-Aside Caching: In Cache-Aside caching, also known as Lazy Loading, the application code is responsible for reading data from the cache when needed. If the data is not in the cache, it is fetched from the data source, and then the application code stores it in the cache for future use.

Write-Through Caching: In Write-Through caching, data is written to the cache and the underlying data source simultaneously. When data is updated or inserted, both the cache and the data source are updated to ensure consistency.

55. What is a Content Delivery Network (CDN), and how does it relate to caching?

A Content Delivery Network (CDN) is a distributed network of servers that deliver web content, such as images, videos, and static files, to users based on their geographical location. CDNs use caching to store and serve content from servers that are geographically closer to the user, reducing latency and improving load times.

56. How do you handle cache synchronization and consistency in a distributed system?

Cache synchronization and consistency can be achieved through strategies like cache expiration, cache purging, and cache versioning. When data changes occur, the cache should be updated or invalidated to ensure that users receive accurate and consistent information
Be cautious about exposing application state to the client, as it can lead to potential security vulnerabilities.

Top comments (0)