What is .NET Framework?
Answer:
The .NET Framework is a software development framework developed by Microsoft that provides a controlled environment for developing, running, and deploying applications. It includes a runtime environment called the Common Language Runtime (CLR) and a Base Class Library (BCL) that supports various programming languages like C#, VB.NET, and F#.
What is CLR (Common Language Runtime)?
Answer:
CLR is the core runtime environment of .NET that manages code execution, memory management, exception handling, security, and garbage collection. It provides features such as Just-In-Time (JIT) compilation and supports multiple programming languages.
What is managed code and unmanaged code?
Answer:
- Managed Code: Code that runs under the control of CLR (e.g., C# code in .NET). CLR manages memory, security, and exception handling.
- Unmanaged Code: Code that is executed directly by the OS, bypassing CLR (e.g., C/C++ code that interacts with system resources).
What is an Assembly in .NET?
Answer:
An assembly is a compiled code library used for deployment, versioning, and security in .NET applications. It contains:
- Metadata (information about types)
- Manifest (assembly version and dependencies)
- MSIL Code (Intermediate Language code)
- Resources (like images or other files)
Types of Assemblies:
- Private Assembly: Used within a single application.
- Shared Assembly: Stored in Global Assembly Cache (GAC) and can be used by multiple applications.
What is Garbage Collection in .NET?
Answer:
Garbage Collection (GC) is an automatic memory management process in .NET that reclaims unused objects and frees memory. The GC has three generations:
- Gen 0: Short-lived objects (e.g., local variables).
- Gen 1: Objects that survived Gen 0 collection.
- Gen 2: Long-lived objects (e.g., static variables, global objects).
What are the different types of JIT Compilers in .NET?
Answer:
.NET uses Just-In-Time (JIT) compilation to convert MSIL (Intermediate Language) into native machine code. There are three types of JIT compilers:
- Normal JIT: Compiles methods as they are called.
- Econo JIT: Compiles methods but does not cache them for future use.
- Pre-JIT (AOT – Ahead of Time): Compiles the entire application code before execution (e.g., using Native Image Generator – NGen).
What is the difference between Stack and Heap memory in .NET?
Answer:
- Stack: Used for storing value types, method calls, and local variables.
- Heap: Used for storing reference types and dynamic memory allocation.
7. What are Value Types and Reference Types in .NET?
Answer:
- Value Types тАУ Stored in Stack (e.g., int, float, bool, char, struct).
- Reference Types тАУ Stored in Heap (e.g., string, class, interface, object).
8. What is the difference between an abstract class and an interface?
Answer:
Feature | Abstract Class | Interface |
---|---|---|
Methods | Can have implemented methods | Only method signatures (no implementation) |
Multiple Inheritance | Not supported | Supported |
Fields | Can have fields and constructors | Cannot have fields |
What is Garbage Collection in .NET?
Answer:
Garbage Collection (GC) in .NET automatically reclaims unused memory, preventing memory leaks. It operates in three generations:
- Gen 0 тАУ Short-lived objects.
- Gen 1 тАУ Medium-lived objects.
- Gen 2 тАУ Long-lived objects.
What is the difference between String and StringBuilder in .NET?
Answer:
- String тАУ Immutable (modification creates a new instance).
- StringBuilder тАУ Mutable (modifications happen in place, improving performance).