Top .NET Interview Questions (2025)

author image Hirely
at 09 Jan, 2025

Question: What is .NET Framework and how does it work?

Answer:

The .NET Framework is a software development platform developed by Microsoft that provides a large class library and supports several programming languages, including C#, VB.NET, and F#. It is used for building and running applications on Windows, including web applications, desktop applications, and services.

The .NET Framework is designed to provide a common environment for developing, deploying, and running applications, ensuring that developers can build software that works across different devices and applications while abstracting much of the complexity involved in interacting with the operating system and hardware.


Key Components of .NET Framework

  1. Common Language Runtime (CLR): The CLR is the execution engine for .NET applications. It manages the execution of code and provides services like garbage collection, exception handling, and type safety. It is responsible for running managed code (code written in a language that is part of the .NET ecosystem, like C#, VB.NET, etc.).

    • Compilation: The CLR uses a Just-In-Time (JIT) compiler to convert Intermediate Language (IL) code into machine code at runtime, which allows the code to run on any platform with a .NET runtime.
    • Memory Management: The CLR automatically manages memory by performing garbage collection, which reclaims memory used by objects that are no longer in use.
    • Security: The CLR provides code access security (CAS) to ensure that code is executed in a secure environment.
  2. Base Class Library (BCL): The BCL is a collection of classes, interfaces, and value types that provide system functionality like file input/output (I/O), networking, database access, and more. It simplifies the development of applications by providing ready-to-use components for many common tasks.

    Examples of namespaces in the BCL:

    • System: Contains fundamental classes like String, DateTime, Exception, etc.
    • System.IO: Provides classes for reading and writing to files and streams.
    • System.Net: Provides classes for networking, such as HttpClient for making HTTP requests.
  3. Common Type System (CTS): The CTS defines how types are declared, used, and managed in the runtime. It ensures that code written in different languages can interact with each other because they all share a common understanding of types.

    • For example, int in C# is mapped to Int32 in the CLR, and string in C# corresponds to String in the CLR.
  4. Common Language Specification (CLS): The CLS is a set of rules that ensures interoperability between different .NET languages. It defines the common set of features that any .NET language should have, which allows components written in different languages to work together seamlessly.


How Does the .NET Framework Work?

  1. Development Stage:

    • Developers write code in a .NET-supported programming language like C#, VB.NET, or F#.
    • The source code is compiled into Intermediate Language (IL) code by the language compiler.
    • The IL code is platform-independent, meaning it can run on any system that has the CLR installed.
  2. Compilation Stage:

    • After the code is compiled into IL, it is packaged into an assembly. An assembly is a file (e.g., .dll or .exe) that contains IL code and metadata about the types, methods, and other components.
  3. Execution Stage:

    • When you run a .NET application, the CLR loads the assembly and converts the IL code into native machine code using the Just-In-Time (JIT) compiler.
    • The JIT compiler compiles the IL code into machine-specific code that is executed by the processor, allowing the application to run.
    • The CLR also handles memory management (garbage collection), exception handling, and security, ensuring that the application runs in a safe and efficient environment.

Key Features of .NET Framework

  1. Language Interoperability:

    • .NET allows different programming languages to work together within the same application. For example, you can write part of your application in C# and another part in VB.NET, and they can interact seamlessly because they all compile to IL and are managed by the CLR.
  2. Garbage Collection:

    • One of the key features of the .NET Framework is automatic memory management. The CLR takes care of allocating and deallocating memory, eliminating the need for developers to manually manage memory (as in languages like C++).
  3. Cross-Platform Development (via .NET Core):

    • While the original .NET Framework was Windows-only, .NET Core (which evolved into .NET 5+) is a cross-platform version of .NET. It supports running applications on Linux, macOS, and Windows, allowing developers to write platform-agnostic code.
  4. Extensive Class Libraries:

    • The BCL provides a large set of libraries that cover a wide range of functionalities, including:
      • File handling (System.IO)
      • Database access (System.Data)
      • Networking (System.Net)
      • Security (System.Security)
      • UI development (Windows Forms, WPF, ASP.NET)
  5. Security:

    • The .NET Framework offers a variety of security features, including code access security (CAS), role-based security, and encryption. These features ensure that applications are safe and that access to resources is controlled.
  6. Exception Handling:

    • .NET provides a consistent exception handling model that allows developers to catch and handle errors across different types of applications.
  7. Type Safety:

    • .NET enforces type safety, ensuring that type mismatches (like trying to store a string in an integer variable) are caught at compile-time or runtime, reducing bugs and improving the reliability of the code.

Components of .NET Framework Architecture

The architecture of the .NET Framework consists of the following key components:

  1. Common Language Runtime (CLR): The engine that executes the code and provides services like garbage collection, exception handling, and security.
  2. Base Class Library (BCL): Provides essential functionality like input/output, data access, security, and threading.
  3. Assemblies: The compiled output of .NET code that contains IL code and metadata.
  4. Application Domain: A container for running applications, providing isolation and ensuring that each application runs independently.
  5. Garbage Collector (GC): Automatically manages memory by reclaiming memory used by objects that are no longer needed.
  6. JIT Compiler: Converts IL code into native machine code at runtime.

Example of How It Works in Practice:

1. Writing Code:

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, World!");
    }
}

2. Compilation:

  • The C# code is compiled into IL code (stored in an .exe or .dll file).

3. Execution:

  • When you run the program, the CLR loads the assembly and invokes the JIT compiler, which translates the IL code into native machine code.
  • The CLR then executes the machine code, displaying the output Hello, World! on the screen.

Summary:

The .NET Framework is a software platform developed by Microsoft that provides a rich environment for building and running applications. It includes the CLR (Common Language Runtime), which handles the execution of code, and the BCL (Base Class Library), which provides essential functionality. The framework ensures language interoperability, memory management, and security, and it abstracts the underlying system to allow developers to focus on writing application logic rather than managing low-level tasks.

The .NET Framework is primarily for Windows, but its cross-platform version, .NET Core (now just .NET 5+), supports Linux and macOS as well.

Question: What is the difference between .NET Framework and .NET Core?

Answer:

The .NET Framework and .NET Core (now known as .NET 5 and later) are both software development platforms developed by Microsoft, but they differ in various aspects, including their scope, platform support, performance, and usage. Here is a detailed comparison between the two:


1. Platform Support

  • .NET Framework:
    • Windows-only: The .NET Framework is designed to run only on Windows. It is tightly integrated with the Windows operating system and can be used to build Windows desktop applications, web applications (via ASP.NET), and other Windows-based applications.
  • .NET Core (and .NET 5+):
    • Cross-platform: .NET Core was created to be platform-agnostic, supporting Windows, Linux, and macOS. This makes it ideal for developing applications that can run on multiple operating systems without modification.
    • .NET 5 and later (simply referred to as .NET) continue the cross-platform approach of .NET Core.

Summary:

  • .NET Framework = Windows-only
  • .NET Core = Cross-platform (Windows, Linux, macOS)
  • .NET 5+ = Cross-platform, replacing .NET Core

2. Application Types Supported

  • .NET Framework:

    • Primarily used for building Windows desktop applications (such as Windows Forms and WPF).
    • Web applications using ASP.NET and ASP.NET MVC (primarily for Windows Server hosting).
    • Used for Windows services, Web APIs, WinForms, and WPF applications.
  • .NET Core (and .NET 5+):

    • Supports building cross-platform applications like web applications, console applications, microservices, cloud applications, and more.
    • ASP.NET Core for web and RESTful APIs (cross-platform).
    • Blazor for building interactive web UIs with C#.
    • Can build mobile applications (via Xamarin integration).
    • Ideal for cloud-native applications, microservices, and Docker-based deployments.

Summary:

  • .NET Framework = Windows desktop apps, ASP.NET apps for Windows, and legacy applications.
  • .NET Core = Cross-platform apps, microservices, web apps, cloud-native apps, and more.

3. Performance

  • .NET Framework:

    • Less optimized for modern workloads: While it’s a mature platform, its performance, particularly in terms of modern workloads, is not as efficient as .NET Core.
    • Tied to older technologies (e.g., Windows communication frameworks, etc.) that can sometimes limit performance.
  • .NET Core (and .NET 5+):

    • High-performance: .NET Core was specifically designed for high performance, especially for web and cloud applications.
    • It includes various optimizations and features like improved Just-in-Time (JIT) compilation, better memory management, and more efficient handling of modern workloads (e.g., microservices and cloud).
    • .NET Core is generally faster than the .NET Framework in most benchmarks.

Summary:

  • .NET Framework = Adequate performance but not optimized for modern workloads.
  • .NET Core = Highly optimized for performance, especially for modern web and cloud applications.

4. Deployment

  • .NET Framework:

    • Global installation: The .NET Framework is installed as part of the Windows operating system. When an application is deployed, it assumes that the appropriate version of the .NET Framework is already installed on the machine.
    • This dependency can lead to versioning issues (e.g., “DLL Hell”).
  • .NET Core (and .NET 5+):

    • Self-contained deployment: One of the most significant features of .NET Core is that applications can be deployed with all of their dependencies. You can package your application with a specific version of .NET Core that is needed, and it can run on any system without requiring the installation of .NET Core separately.
    • This reduces the risk of version conflicts and ensures the application is always using the required version.

Summary:

  • .NET Framework = Requires the framework to be installed on the machine.
  • .NET Core = Can be deployed with its own runtime, making it easier to manage version dependencies.

5. API and Libraries

  • .NET Framework:

    • Full feature set: .NET Framework has been around for many years, so it has a large and mature set of libraries and APIs, covering a wide range of application types, including web, desktop, database, and Windows-specific technologies (e.g., Windows Forms, WPF).
    • It includes technologies like Web Forms, WCF, Windows Communication Foundation, and Windows-specific APIs that are not available in .NET Core.
  • .NET Core (and .NET 5+):

    • Subset of libraries: When it was first released, .NET Core had a smaller set of APIs compared to the .NET Framework. However, this gap has significantly narrowed with the release of .NET Core 3.0 and .NET 5+.
    • It includes modern alternatives like ASP.NET Core for web development, and Entity Framework Core for data access, but it does not include older, Windows-only technologies such as Web Forms or WCF.
    • With .NET 5 and later, many features from the .NET Framework have been incorporated, but it is still missing certain legacy features specific to Windows environments.

Summary:

  • .NET Framework = More mature, full feature set, including legacy APIs for Windows-specific applications.
  • .NET Core = Modern, minimalistic APIs, focusing on cross-platform development, with some legacy features still missing.

6. Ecosystem and Support

  • .NET Framework:

    • Long-term support: The .NET Framework is still supported, but Microsoft has shifted its focus to .NET Core (and now .NET 5+). New features and improvements are no longer being actively added to the .NET Framework, and it is considered more of a legacy platform.
    • Applications using the .NET Framework will still receive security updates, but major new developments are expected to occur in .NET Core and later versions.
  • .NET Core (and .NET 5+):

    • Active development and improvements: .NET Core and .NET 5+ are actively developed and are the future of the .NET ecosystem.
    • Microsoft is making substantial investments in performance improvements, security, cloud-native development, and cross-platform capabilities.
    • Unified platform: .NET Core has evolved into .NET 5+ to unify the platform for all types of development, including web, desktop, mobile, cloud, and more.

Summary:

  • .NET Framework = Legacy platform, with ongoing support but no new major features.
  • .NET Core = Actively developed, with future support and continued improvements in performance, cross-platform development, and more.

7. Web Development

  • .NET Framework:

    • ASP.NET Web Forms and ASP.NET MVC for web applications.
    • Less flexibility and scalability for modern, cloud-based, or microservices-based web applications.
  • .NET Core (and .NET 5+):

    • ASP.NET Core: A cross-platform, high-performance web framework that allows for building scalable web applications, APIs, and microservices. It is much faster and more flexible than the ASP.NET Framework.
    • ASP.NET Core enables modern web practices like single-page applications (SPA), REST APIs, and GraphQL.

Summary:

  • .NET Framework = Older web technologies (Web Forms, MVC).
  • .NET Core = Modern, cross-platform web development with ASP.NET Core.

Summary of Differences

Feature.NET Framework.NET Core (and .NET 5+)
PlatformWindows-onlyCross-platform (Windows, Linux, macOS)
Application TypesDesktop apps (WinForms, WPF), Web appsWeb apps, microservices, cloud apps
PerformanceLess optimized for modern workloadsHigh-performance, optimized for modern apps
DeploymentRequires installation of .NET FrameworkCan be self-contained with dependencies
API/LibraryFull set of APIs, including legacy onesModern, cross-platform APIs
EcosystemLegacy, less active developmentActively developed, future of .NET
Web DevelopmentASP.NET Web Forms and MVCASP.NET Core, REST APIs, Blazor

Conclusion:

  • .NET Framework is a mature platform that is ideal for building traditional Windows-based applications and legacy systems. However, it is Windows-only, and new features are no longer being actively added.
  • .NET Core (and .NET 5+) is the modern, cross-platform framework designed for high-performance, scalable applications, including web applications, cloud-native apps, and microservices. It is actively developed and supports a wide range of platforms.

For new projects, .NET Core (or .NET 5+) is the recommended choice due to its performance, cross-platform support, and modern architecture.

Read More

If you can’t get enough from this article, Aihirely has plenty more related information, such as .NET interview questions, .NET interview experiences, and details about various .NET job positions. Click here to check it out.

Related Posts

Trace Job opportunities

Hirely, your exclusive interview companion, empowers your competence and facilitates your interviews.

Get Started Now