1. What is .NET Framework?
ANS: .NET Framework is a software development framework created by Microsoft for building and running applications on Windows. It provides a consistent object-oriented programming environment with a rich set of libraries for building desktop, web, and mobile applications. It supports multiple languages like C#, VB.NET, and F#, and includes the Common Language Runtime (CLR) for memory management, exception handling, and security.
2. What is the CLR in .NET?
ANS: The Common Language Runtime (CLR) is the runtime environment in the .NET Framework that handles the execution of code. It provides services like memory management, garbage collection, security, and exception handling. The CLR ensures that .NET applications run efficiently and securely by managing resources and enforcing code safety.
3. What is the difference between .NET Core and .NET Framework?
ANS: .NET Framework is designed for building Windows applications, while .NET Core is a cross-platform framework for building modern cloud, IoT, and mobile applications. .NET Core is more modular and supports Linux, macOS, and Windows, unlike .NET Framework which is limited to Windows. .NET Core offers better performance and scalability for microservices and cloud applications.
Q4. What is the purpose of the Garbage Collector (GC) in .NET?
ANS: The Garbage Collector (GC) in .NET automatically manages memory by freeing up unused objects from the heap. It reduces memory leaks and eliminates the need for developers to manually allocate and deallocate memory. The GC works in generations (0, 1, and 2) to optimize the collection of short-lived and long-lived objects.
Q5. What are assemblies in .NET?
ANS: An assembly is the building block of a .NET application. It is a compiled code library used by the CLR for deployment, versioning, and security. Assemblies can be DLLs (Dynamic Link Libraries) or EXE files. Assemblies contain metadata and IL (Intermediate Language) code and can be either private or shared (GAC – Global Assembly Cache).
Q6. What is the difference between managed and unmanaged code?
ANS: Managed code is executed by the CLR and benefits from features like garbage collection, security, and type safety. Unmanaged code is executed directly by the OS, without CLR intervention, and requires manual memory management.
Q7. Explain the concept of boxing and unboxing in .NET.
ANS: Boxing is the process of converting a value type to an object type while unboxing converts an object type back to a value type. Boxing wraps the value inside an object, and unboxing extracts the value from the object.
Q8. What is the difference between an interface and an abstract class in .NET?
ANS: An interface defines a contract with no implementation, while an abstract class can contain both abstract methods (without implementation) and non-abstract methods (with implementation). Interfaces support multiple inheritances, whereas a class can only inherit from one abstract class.
Q9. What is LINQ in .NET?
ANS: LINQ (Language Integrated Query) is a query syntax in .NET that is used to query collections, databases, XML, and more. It provides a unified approach to querying different data sources using a consistent syntax. LINQ allows developers to write queries in C# or VB.NET in a readable and efficient way.
Q10. What is the role of the JIT compiler in .NET?
ANS: The Just-In-Time (JIT) compiler in .NET compiles the Intermediate Language (IL) code into machine code just before execution. This allows .NET applications to be platform-independent until runtime, where the IL code is converted to native machine code for the target platform. The JIT optimizes performance by compiling only the code needed for execution.
Q11. What is ADO.NET in .NET?
ANS: ADO.NET is a data access technology in .NET for interacting with databases. It provides classes to connect to databases, execute commands, retrieve results, and manage data. ADO.NET supports connected and disconnected architectures using SqlConnection, SqlCommand, DataSet, and other classes.
Q12. What is .NET Standard?
ANS: .NET Standard is a specification that defines a set of APIs that must be implemented by all .NET platforms (e.g., .NET Core, .NET Framework, Xamarin). It ensures compatibility across different .NET platforms, enabling developers to create libraries that work everywhere. .NET Standard allows for greater code sharing between different platforms.
Q13. What are generics in .NET?
ANS: Generics in .NET allow you to define classes, methods, and interfaces with type parameters. They provide type safety and performance by allowing code reusability without the need for boxing/unboxing. Generics are used in collections like List<T>, Dictionary<TKey, TValue>, etc.
Q14. What is the Global Assembly Cache (GAC) in .NET?
ANS: The Global Assembly Cache (GAC) is a repository in .NET that stores shared assemblies that can be used by multiple applications. Assemblies in the
GAC are versioned, enabling applications to use specific versions of shared libraries. Assemblies must be strongly named to be added to the GAC.
Q15. What is Entity Framework in .NET?
ANS: Entity Framework (EF) is an Object-Relational Mapper (ORM) that allows developers to interact with databases using .NET objects instead of SQL queries. EF supports LINQ to query the database and simplifies CRUD operations. Entity Framework makes data access more abstract, allowing developers to work with data as objects and properties.
Q16. What is the difference between a Task and Thread in .NET?
ANS: Task represents an asynchronous operation, while Thread represents a separate path of execution. Tasks in .NET are used for managing asynchronous operations and work at a higher level of abstraction than threads. Tasks make it easier to handle parallelism and are optimized for resource management.
Q17. What is the role of async and await in .NET?
ANS: async and await are used to write asynchronous code in .NET. The async modifier is applied to methods that perform asynchronous operations, and await is used to pause the execution until the awaited task is completed. Async programming helps prevent blocking the main thread and improves responsiveness in applications.
Q18. What is the difference between IEnumerable and IQueryable in .NET?
ANS: IEnumerable is used for iterating over in-memory collections and works well with LINQ-to-Objects. IQueryable is used for querying data sources, like databases, and performs queries on the server-side. IQueryable provides better performance for large datasets because it generates database-specific queries, while IEnumerable fetches all data into memory before processing.
Q19. What is .NET Core, and how is it different from .NET Framework?
ANS: .NET Core is a cross-platform, open-source framework for building modern applications, whereas .NET Framework is limited to Windows. .NET Core supports cloud-based, IoT, and microservice architectures and offers
better performance and scalability compared to .NET Framework. .NET Core is modular and lightweight, making it suitable for containerized applications.
Q20. What is ASP.NET Core?
ANS: ASP.NET Core is a cross-platform framework for building modern web applications. It is a modular framework that allows for high-performance and scalable applications. ASP.NET Core unifies MVC and Web API into a single framework. ASP.NET Core supports dependency injection, middleware, and cross-platform deployment.
Browse our course links: .NET Training in Pune
To Join our FREE DEMO Session: Click Here
Q21. What is Dependency Injection (DI) in .NET?
ANS: Dependency Injection (DI) is a design pattern in which dependencies (services) are injected into a class, rather than being created inside the class. This promotes loose coupling and enhances testability and maintainability. ASP.NET Core has built-in support for DI, allowing you to register services in the Startup.ConfigureServices() method.
Q22. What is the purpose of the appsettings.json file in .NET Core?
ANS: appsettings.json is used to store configuration settings for a .NET Core application. It contains settings like connection strings, API keys, and environment-specific configurations. The contents are loaded into the application’s configuration at runtime and can be accessed using the IConfiguration interface. .NET Core supports environment-specific configurations through files like appsettings.Development.json.
Q23. What are extension methods in .NET?
ANS: Extension methods allow you to add new methods to existing types without modifying the original class or creating a new derived type. They are defined as static methods in static classes, and the first parameter of the method specifies the type it extends. Extension methods improve code readability and maintainability by adding functionality to existing types.
Q24. What is the Task Parallel Library (TPL) in .NET?
ANS: The Task Parallel Library (TPL) in .NET provides a framework for parallel programming and efficient task management. It simplifies writing concurrent and asynchronous code by using Task objects to represent asynchronous operations. TPL improves performance by utilizing multi-core processors and simplifying code structure for parallel operations.
Q25. What is MVC in .NET?
ANS: MVC (Model-View-Controller) is a design pattern used in ASP.NET Core and .NET Framework to separate an application’s concerns. The Model represents the data, the View displays the UI, and the Controller handles user input and interactions. The MVC pattern promotes modularity and makes applications more maintainable by separating logic, UI, and data access.
Q26. What is SignalR in .NET?
ANS: SignalR is a library in .NET used for adding real-time web functionality to applications. It enables the server to push content to connected clients instantly, supporting features like chat applications, live dashboards, and notifications. SignalR abstracts communication technologies like WebSockets and Long Polling to provide real-time communication.
Q27. What is a delegate in .NET?
ANS: A delegate in .NET is a type that represents references to methods with a specific signature. Delegates are used to pass methods as arguments to other methods and are the foundation of events and callback methods. Delegates provide flexibility by allowing methods to be treated as first-class objects.
Q28. What is a lambda expression in .NET?
ANS: A lambda expression is a concise way to represent anonymous methods in .NET. Lambda expressions are used extensively in LINQ queries, event handling, and asynchronous programming. They provide a more readable and functional style of writing code, allowing inline definitions of small methods.
Q29. What is an event in .NET, and how is it used?
ANS: An event in .NET is a way for objects to notify other objects when something of interest occurs. Events are based on delegates and follow the publisher-subscriber model, where an event is raised by one object (publisher), and other objects (subscribers) respond to it. Events are commonly used in GUIs, where user actions like button clicks trigger events.
Q30. What is REST, and how do you implement it in .NET?
ANS: REST (Representational State Transfer) is an architectural style for building web services that interact using HTTP methods like GET, POST, PUT, and DELETE. RESTful services are stateless and use URLs to represent resources. In .NET, REST APIs are typically implemented using ASP.NET Core or ASP.NET Web API, with methods mapped to HTTP verbs.
Q31. What is async and await in .NET, and why are they important?
ANS: async and await are used to simplify asynchronous programming in .NET. They allow methods to run asynchronously without blocking the main thread, making the application more responsive, especially for I/O-bound tasks like network requests. await is used to wait for the completion of an asynchronous operation, while async marks the method that contains asynchronous code.
Q32. What is a struct in .NET?
ANS: A struct in .NET is a value type used to encapsulate small groups of related variables, such as the coordinates of a point. Unlike classes, structs are stored on the stack and have value semantics, meaning they are copied when passed to functions. structs are suitable for small data objects and can be used for performance-critical operations.
Q33. What is the difference between const and read-only in .NET?
ANS: const defines a compile-time constant, while read-onlya defines a runtime constant that can only be assigned in the constructor. const fields are static and cannot be changed after compilation, while read-only fields can be initialized at runtime. read-only is often used when the value needs to be constant after object creation but is not known at compile time.
Q34. What are attributes in .NET?
ANS: Attributes in .NET are used to add metadata to code elements such as classes, methods, or properties. Attributes provide additional information to the runtime or compiler, such as indicating obsolete code or requiring special permissions. Attributes are placed directly above the code they affect and are processed at runtime via reflection.
Q35. What is reflection in .NET?
ANS: Reflection in .NET allows programs to inspect and manipulate their own metadata at runtime. It provides the ability to dynamically discover types, methods, properties, and fields in assemblies. Reflection is often used in frameworks, serialization, and for accessing private members of classes. Reflection can also be used to create instances of types dynamically.
Q36. What is the difference between finalize and dispose in .NET?
ANS: Finalize is used for cleanup by the garbage collector and is automatically called when an object is being collected, whereas Dispose is explicitly called to release unmanaged resources before the object is collected. Dispose is part of the IDisposable interface and provides a deterministic way to clean up resources like file handles or database connections.
Q37. What are the key differences between List and Array in .NET?
ANS: Arrays have a fixed size, while List<T> is a dynamic collection that can grow or shrink as needed. Arrays can store elements of a specific type, whereas List<T> is a generic class that allows for type-safe storage of elements with more flexible operations like Add and Remove. List<T> also provides more built-in functionality for operations like searching, sorting, and filtering.
Q38. What is a namespace in .NET, and why is it important?
ANS: A namespace is a way to organize and group related classes, interfaces, enums, and other elements in .NET. It helps prevent naming conflicts by distinguishing between classes with the same name but in different namespaces. Namespaces provide a logical hierarchy and make code easier to maintain by grouping related functionality together.
Q39. What is a sealed class in .NET?
ANS: A sealed class in .NET cannot be inherited by other classes. It is useful when you want to prevent further derivation, typically for reasons related to security, performance, or design. Sealing a class ensures that the class cannot be extended, which may enhance stability and prevent accidental overrides.
Q40. What is the IDisposable interface in .NET?
ANS: The IDisposable interface defines a method Dispose() that is used to release unmanaged resources, such as file handles or database connections, when they are no longer needed. It provides a standardized way to perform cleanup operations, and objects that use unmanaged resources should implement IDisposable.
Q41. What is asynchronous programming, and how is it implemented in .NET?
ANS: Asynchronous programming allows for non-blocking execution, meaning tasks can run in the background without stopping the main thread. It is implemented using async and await keywords in .NET. This is especially useful for I/O-bound operations, such as reading from files or making HTTP requests, as it prevents UI freezing or unnecessary thread blocking.
Q42. What are properties in .NET?
ANS: Properties in .NET are members of a class that provide a flexible mechanism to access and modify data fields. They use get and set accessors to encapsulate the fields of a class. Properties are a safer way to expose class data compared to public fields because you can control the logic in the get or set methods.
Q43. What is polymorphism in .NET?
ANS: Polymorphism in .NET is the ability of different classes to be treated as instances of the same base class. It allows one method to have different implementations based on the derived class. Polymorphism can be achieved through method overriding (runtime polymorphism) and method overloading (compile-time polymorphism).
Q44. What is an enum in .NET?
ANS: An enum is a special value type in .NET that defines a set of named constants. Enums are used to represent a collection of related constants, such as days of the week, user roles, or states. Enums improve code readability by giving meaningful names to numeric values.
Q45. What is an exception in .NET, and how is it handled?
ANS: An exception in .NET is an error that occurs during the execution of a program. Exceptions are handled using try-catch-finally blocks. In the catch block, you can define the logic for dealing with the exception, while the final block is used for code that must execute whether an exception occurs or not. Proper exception handling ensures that your application can gracefully handle errors and continue running.
Q46. What are the access modifiers in .NET?
ANS: Access modifiers in .NET define the scope and visibility of classes and their members. The main access modifiers are:
public: Accessible from anywhere.
private: Accessible only within the same class.
protected: Accessible within the same class and by derived classes.
internal: Accessible only within the same assembly.
protected internal: Accessible by derived classes or within the same assembly.
Q47. What is the difference between overloading and overriding in .NET?
ANS: Overloading occurs when two or more methods in the same class have the same name but different parameters (method signatures). Overriding happens when a derived class provides a specific implementation for a method that is already defined in the base class. Overloading is a compile-time feature while overriding is a runtime feature.
Q48. What is the purpose of the default keyword in .NET?
ANS: The default keyword in .NET is used to assign default values to value types and reference types. For value types like int, the default assigns 0, and for reference types, it assigns null. This keyword is useful in generic programming to handle cases where you don’t know the type at compile-time but still want to initialize it.
Browse our course links: .NET Training in Pune
To Join our FREE DEMO Session: Click Here
Q49. What is an Indexer in .NET?
ANS: An indexer allows instances of a class to be indexed like arrays. It lets you define how to access and set values within an object using array-like syntax, improving usability. Indexers are useful when you want a class to behave like a collection.
Q50. What is a Nullable type in .NET?
ANS: A Nullable type allows value types, such as int or bool, to represent null values. In .NET, the Nullable<T> structure or the shorthand T? is used to allow value types to have null as a valid value. Nullable types are useful when working with databases or scenarios where a value may not always be present.
Q51. What are some of the common components of .NET?
ANS: There are a lot of components that make up the .NET framework, and some of them are as follows:
.NET Class Library
.NET Framework
Language Runtime
Application Domain
Profiling
Q52. What does JIT stand for in .NET?
ANS: JIT is the abbreviation of Just in Time. It is a compiler that is used to convert intermediate code into native code easily. In .NET, during execution, the code is converted into the native language, also called the byte code. This is processed by the CPU, and the framework helps with the conversion.
Q53. What is the meaning of MSIL?
ANS: MSIL is the abbreviation for Microsoft Intermediate Language. It is used to provide the instructions required for operations such as memory handling, exception handling, and more. It can also provide instructions to initialize and store values and methods easily.
Q54. What is CTS?
ANS: The acronym CTS stands for Common Type System, which encompasses a predefined set of systematic regulations dictating the proper definition of data types in relation to the values provided by a user. Its primary purpose is to characterize and encompass all the various data types utilized within a user’s application. Nevertheless, it is also permissible for users to construct custom calls using the guidelines established by the CTS. This feature is primarily provided to accommodate the diverse range of programming languages that can be employed when working within the .NET framework.
Q55. What is CLS?
ANS: CLS stands for Common Language Specification in .NET. It is put into place to ensure that the application developer is capable of inter-language operations if required. It is a reusable aspect among all of the .NET compatible languages.
Q56. What is the meaning of state management in .NET?
ANS: State management, as the name suggests, is used to constantly monitor and maintain the state of objects in the runtime. A web page or a controller is considered to be an object.
There are two types of state management in ASP.NET:
1. Client-side: It is used to store information on the client’s machine and is formed mostly of reusable and simple objects.
2. Server-side: It stores the information on the server and makes it easier to manage and preserve the information on the server.
Next up on this top .net interview questions for freshers and experienced, let us understand the difference between an object and a class.
Q57. What is the meaning of LINQ?
ANS: LINQ is the abbreviated form of Language Integrated Query. It was first brought out in 2008, and it provides users with a lot of extra features when working with the .NET framework. One highlight is that it allows the users to manipulate data without any dependency on its source.
Q58. What is an assembly in .NET?
ANS: An assembly is the simple collection of all of the logical units present. Logical units are entities that are required to build an application and later deploy the same using the .NET framework. It can be considered as a collection of executables and DLL files.
Q59. What are some of the components of an assembly in .NET?
ANS: There are four main components of an assembly. They are as follows:
Resource: A collection of related files
MSIL: The Intermediate Language code
Metadata: The binary data of a program
Manifest: A collection of information about the assembly
Q60. What is the meaning of caching?
ANS: Caching is a term used when the data has to be temporarily stored in the memory so that an application can access it quickly rather than looking for it in a hard drive. This speeds up the execution to an exponential pace and helps massively in terms of performance.
There are three types of caching:
Data caching
Page caching
Fragment caching
Q61. What are some of the advantages of using a session?
ANS: There are numerous advantages of making use of a session are as mentioned below:
It is used to store user data across the span of an application.
It is very easy to implement and store any sort of object in the program.
Individual entities of user data can be stored separately if required.
The session is secure, and objects get stored on the runtime server.
Q62. Is it possible to manually set a timeout for a session in .NET?
ANS: Yes, it is possible to manually set a session’s out time. It can easily be done by manipulating the web.config file.
Next up in this set of top .NET interview questions for freshers and experienced developers, we can take a look at the questions categorized as intermediate!
Q63. What is the meaning of boxing and unboxing in .NET?
ANS: Boxing is the process that is used when a user wishes to convert a value type into a reference type directly.
Unboxing is the opposite of boxing, where the reference type is converted back into a value type.
Q64. What is the use of manifest in the .NET framework?
ANS: Manifest is mainly used to store the metadata of the assembly. It contains a variety of metadata which is required for many things as given below:
Assembly version information
Security identification
Scope checking of the assembly
Reference validation of classes
Q65. What are memory-mapped files used for in .NET?
ANS: Memory-mapped files in .NET are used to instantiate the contents of a logical file into the address of the application. This helps a user run processes simultaneously on a single machine and have the data shared between processes. The MemoryMappedFile.The CreateFromFiles() function is used to obtain a memory-mapped file object easily.
Q66. What is the meaning of CAS in .NET?
ANS: CAS stands for Code Access Security. It is vital in the prevention of unauthorized access to programs and resources in the runtime. It can provide limited access to the code to perform only certain operations rather than providing all at a given point in time. CAS forms to be a part of the native .NET security architecture.
Q67. What are the types of memories supported in the .NET framework?
ANS: There are two types of memories present in .NET as listed below:
Stack: Used for static memory allocation
Heap: Used for dynamic memory allocation
Q68. What is the meaning of AutoPostBack in .NET?
ANS: AutoPostBack is a property in the .NET framework, which provides automatic postback whenever an event starts its execution cycle. To use AutoPostBack, you have to set the property to True.
Q69. What are the parameters that control connection pooling behaviors in .NET?
ANS: There are four main parameters that control connection pooling behaviors in .NET as given below:
Connect Timeout
Min Pool Size
Max Pool Size
Pooling
Q70. What are the requirements needed for connection pooling?
ANS: Three main requirements to be fulfilled for connection pooling are as explained below:
The presence of an identical connection string for both entities
The existence of multiple processes with the same connection parameters
The presence of similar security protocols and settings
Browse our course links: .NET Training in Pune
To Join our FREE DEMO Session: Click Here
These questions are designed to evaluate a candidate's skills in the .NET framework. The goal is to assess competency in application design, development, and maintenance. Successfully answering these .NET Interview questions showcases a candidate's technical abilities and problem-solving skills within the .NET ecosystem. Preparation is key for those seeking. NET-related positions. Therefore, understanding these questions is crucial for job seekers.
Get More Information