Top 100 ASP.NET Core Interview Questions and Answers for 2024 PART - 2

 Top 100 ASP.NET Core Interview Questions and Answers for 2024 PART - 2


11.) Is it possible to view the IL code?

 

- Yes, it is possible to view the IL code using tools like IL Disassembler (ildasm.exe) or .NET Reflector.

- These tools allow developers to inspect the IL code generated by the compiler and understand how their source code is translated into intermediate language instructions.

 

12.) What is a CLR?

 

- CLR (Common Language Runtime) is the virtual machine component of the .NET framework responsible for executing managed code.

- It provides various services, including memory management, exception handling, type safety, and garbage collection, to ensure the secure and efficient execution of .NET applications.

 

 

13.) Difference between managed and unmanaged code:

 

- Managed Code:

  - Code executed by the Common Language Runtime (CLR) in the .NET framework.

  - Provides automatic memory management, garbage collection, and runtime environment services.

  - Written in high-level languages like C#, VB.NET, or F#.

  - Runs within a managed environment, ensuring safety and security through features like type-safety and memory management.

 

- Unmanaged Code:

  - Code executed directly by the operating system without the assistance of a runtime environment like the CLR.

  - Typically written in low-level languages like C or C++.

  - Developers are responsible for manual memory management, resource allocation, and deallocation.

  - Unmanaged code can directly interact with system resources and hardware, offering more control but also requiring careful handling to avoid memory leaks and security vulnerabilities.

 

14.) What is a garbage collector?

 

- A garbage collector is a component of the CLR responsible for automatic memory management in managed code.

- It identifies and removes objects from memory that are no longer in use, freeing up memory resources and preventing memory leaks.

 

15.) What are generations in Garbage collector (Gen 0, 1 and 2)?

 

- Generations in the garbage collector refer to different categories of objects based on their age and longevity in memory.

- Gen 0: Newly allocated objects reside in Gen 0. These objects are typically short-lived and are collected frequently.

- Gen 1: Objects that survive Gen 0 collections are promoted to Gen 1. These objects have a longer lifespan but are still subject to periodic collections.

- Gen 2: Objects that survive Gen 1 collections are promoted to Gen 2. These objects have the longest lifespan and are collected less frequently.

 

16.)  Garbage collector cleans managed code, how do we clean unmanaged code?

 

- Unmanaged code requires manual memory management, meaning developers must explicitly allocate and deallocate memory resources using functions like malloc() and free() in C or C++.

- Cleaning unmanaged code involves releasing resources using appropriate cleanup mechanisms, such as calling free() to release memory allocated with malloc().

 

17.) But when we create a destructor the performance falls down? So how can we clean unmanaged objects and also maintain performance?

 

- Destructors in C# (denoted by the ~ symbol) are called finalizers and are used to release unmanaged resources.

- However, relying solely on destructors for resource cleanup can impact performance due to the non-deterministic nature of garbage collection.

- To clean unmanaged objects efficiently while maintaining performance, it's recommended to implement the IDisposable interface and use the Dispose() method to explicitly release resources when they are no longer needed.

 

18.) Can we force garbage collector to run?

 

- Yes, you can force the garbage collector to run using the System.GC.Collect() method.

- However, manual garbage collection is generally not recommended as the CLR's automatic garbage collection mechanism is optimized to run at appropriate times based on memory pressure and resource usage.

 

19.) What is the difference between finalize and dispose?

 

- Finalize is a method called by the garbage collector to perform cleanup of unmanaged resources before an object is destroyed.

- Dispose is a method implemented by classes that manage unmanaged resources, allowing developers to explicitly release these resources when they are no longer needed.

- Finalize is non-deterministic and relies on garbage collection, while Dispose provides deterministic cleanup and should be called explicitly by the developer.

 

20.) What is CTS?

 

- CTS (Common Type System) is a standard that defines how types are declared, used, and managed in the .NET framework.

- It ensures interoperability between languages by defining a common set of data types and rules for type interactions.

 


Top 100 ASP.NET Core Interview Questions and Answers for 2024 PART - 3 --- Coming soon