Skip to main content

Classic .Net interview questions and answers

Question: What is .NET Framework?
Answer: .NET Framework is a software framework developed by Microsoft that primarily runs on Microsoft Windows. It provides a large class library and supports several programming languages. It is used for building, deploying, and running applications and services that use .NET technologies.

Question: What are the main components of .NET Framework?
Answer: 
  • Common Language Runtime (CLR)
  • Class Library (FCL)
  • Common Type System (CTS)
  • Common Language Specification (CLS)
Explain the Common Language Runtime (CLR).
Answer: CLR is the execution engine of the .NET Framework. It provides various services such as memory management, exception handling, security management, and thread management. It also performs tasks such as compilation of source code into intermediate language, garbage collection, and JIT (Just-In-Time) compilation.

Question: What is the difference between value types and reference types in C#?
Answer: Value types store their data in the memory location where the variable is declared. They include simple types like int, float, struct, etc. Reference types, on the other hand, store a reference to the memory location where the data is actually stored. They include classes, interfaces, delegates, etc.

Question: What is Garbage Collection?
Answer: Garbage Collection is the process by which the .NET runtime environment automatically manages memory. It identifies and collects objects that are no longer being used by the application and deallocates their memory, thus preventing memory leaks and improving application performance.

Question: What is the difference between managed code and unmanaged code?
Answer: Managed code is code that is executed by the CLR and benefits from CLR services like automatic memory management, type safety, and exception handling. Unmanaged code, on the other hand, is code that is executed directly by the operating system without the CLR's intervention. Examples include code written in C or C++.

Question: What are assemblies in .NET?
Answer: Assemblies are the building blocks of .NET applications. They are self-describing units of deployment that contain compiled code (IL), metadata, and resources. Assemblies can be either executables (EXE) or libraries (DLL) and can be private or shared.

Question: Explain the difference between an abstract class and an interface in C#.
Answer: An abstract class can contain both abstract and non-abstract (concrete) members, while an interface can only contain abstract members. A class can inherit from only one abstract class, but it can implement multiple interfaces. Abstract classes can have access modifiers while interfaces cannot.

Question: What is Boxing and Unboxing in C#?
Answer: Boxing is the process of converting a value type to a reference type, while unboxing is the process of converting a reference type to a value type. This conversion involves allocating memory in the heap (for boxing) and extracting the value from the heap (for unboxing), which can impact performance.

Question: Explain the concept of namespaces in C#.
Answer: Namespaces are used to organize code into logical groups and prevent naming conflicts. They provide a way to uniquely identify types within a .NET application. They can be nested, and classes within a namespace can be accessed using the dot notation.

Question: What is the difference between an interface and an abstract class in C#?
Answer: Interfaces can only declare method signatures, properties, events, and indexers but cannot provide implementation, while abstract classes can contain both abstract and non-abstract members with implementation. Classes can implement multiple interfaces but can inherit from only one abstract class.

Question: Explain the use of the 'using' statement in C#.
Answer: The 'using' statement in C# is primarily used for resource management, especially for objects that implement IDisposable interface. It ensures that the Dispose method of the object is called when the scope of the 'using' block is exited, thus releasing unmanaged resources and providing better memory management.

Question: What are delegates in C#?
Answer: Delegates in C# are type-safe function pointers that can reference methods with a specific signature. They allow methods to be passed as parameters to other methods, encapsulating a reference to a method within an object. Delegates are widely used in event handling and callback mechanisms.

Question: Explain the concept of garbage collection generations in .NET.
Answer: Garbage collection in .NET categorizes objects into generations based on their lifetime. 
There are typically three generations: 
  • Generation 0, 
  • Generation 1, and 
  • Generation 2. 
Newly created objects start in Generation 0 and are promoted to higher generations if they survive garbage collection cycles. Higher generation objects have longer lifetimes and are collected less frequently.

Question: What is the Global Assembly Cache (GAC) in .NET?
Answer:
The Global Assembly Cache (GAC) is a machine-wide repository in .NET for storing shared assemblies. It allows multiple applications to share assemblies without having multiple copies of the same assembly on disk. Assemblies deployed in the GAC must have a strong name, which includes a unique identity, version information, and a digital signature.

Question: Explain the concept of Exception Handling in C#.
Answer:  Exception handling in C# allows developers to gracefully handle runtime errors and unexpected conditions in their code. It involves using try, catch, finally, and throw keywords. Code that might throw an exception is enclosed in a try block, and exceptions are caught and handled in catch blocks. The finally block is used to execute cleanup code regardless of whether an exception occurs.

Question: What is ASP.NET and how does it differ from .NET Framework?
Anwer: ASP.NET is a web application framework developed by Microsoft for building dynamic web sites, web applications, and web services. It is built on top of the .NET Framework and provides additional libraries and tools specifically for web development. While .NET Framework is a general-purpose framework for building various types of applications, ASP.NET is tailored specifically for web development.

Question: What is the role of the Web.config file in ASP.NET?
Answer: The Web.config file in ASP.NET is a configuration file that contains settings and configurations for ASP.NET web applications. It allows developers to customize various aspects of the application such as session state, authentication, authorization, error handling, and more. Changes made to the Web.config file are automatically detected by ASP.NET and applied without requiring the application to be recompiled.

Question: What is the role of the App.config file in .NET applications?
Answer: The App.config file, also known as the application configuration file, is used to store configuration settings for .NET applications. It is particularly used for desktop and console applications. The settings stored in App.config can include connection strings, application settings, custom configurations, and more. At runtime, the App.config settings are read by the ConfigurationManager class and made available to the application.

Question: Explain the purpose of the ConfigurationManager class in .NET.
Answer: The ConfigurationManager class in .NET is used to access configuration settings from configuration files such as App.config and Web.config. It provides methods and properties to read configuration sections, connection strings, and application settings defined in these configuration files. It allows developers to access configuration settings in a convenient and consistent manner from their code.

Question: What is ASP.NET Core? How does it differ from ASP.NET Framework?
Answer: ASP.NET Core is a cross-platform, open-source web framework developed by Microsoft. It is a complete rewrite of ASP.NET and is optimized for modern web development scenarios. Unlike ASP.NET Framework, which is tied to Windows and IIS, ASP.NET Core can run on Windows, Linux, and macOS. It is also modular, lightweight, and offers better performance and scalability compared to ASP.NET Framework.

Question: Explain the concept of Dependency Injection (DI) in ASP.NET Core.
Answer: Dependency Injection (DI) in ASP.NET Core is a design pattern used to achieve loose coupling between components in an application. It allows classes to define their dependencies through constructor parameters or properties, and a container (e.g., built-in or third-party IoC container) injects these dependencies at runtime. DI promotes easier unit testing, better maintainability, and flexibility in changing implementations.

Question: What are Middleware in ASP.NET Core?
Answer: Middleware in ASP.NET Core are components that handle requests and responses in the application's request processing pipeline. Each middleware component in the pipeline processes the HTTP request or response in some way, such as logging, authentication, authorization, routing, etc. Middleware components are executed in the order they are added to the pipeline and can be added, removed, or reordered dynamically.

Question: Explain the concept of Entity Framework (EF) in .NET.
Answer: Entity Framework (EF) is an Object-Relational Mapping (ORM) framework in .NET that enables developers to work with relational databases using object-oriented techniques. It allows developers to interact with databases using strongly-typed objects (entities) instead of raw SQL queries. EF provides features such as LINQ to Entities for querying data, automatic change tracking, and database migrations for schema changes.

Question: What is ASP.NET MVC? How does it differ from Web Forms?
Answer: ASP.NET MVC is a web application framework for building Model-View-Controller (MVC) based web applications. It provides a pattern-based way to build dynamic websites by separating the application into three main components: models (data), views (UI), and controllers (logic). Unlike Web Forms, which follows a stateful, event-driven programming model, ASP.NET MVC follows a more lightweight, stateless, and testable architecture.

Comments

Popular posts from this blog

Angular Question and Answer

Angular Basics Questions Question: What is Angular? Answer:  Angular is an open-source front-end web framework developed and maintained by Google. It's a platform that allows developers to build dynamic, single-page web applications (SPAs) and progressive web apps (PWAs) with ease. Angular utilizes HTML as its template language and extends its syntax with directives to express the application's components more clearly. One of the distinctive features of Angular is its two-way data binding, which enables automatic synchronization of data between the model and the view. This means that changes made in the application's data reflect instantly in the UI, and vice versa. Question:  What are the key features of Angular? Answer:  Angular is a comprehensive framework that offers a variety of features to facilitate the development of robust and maintainable web applications. Some of its key features include: Component-Based Architecture: Angular follows a component-based architec...

OOPS Concept

  Basic Concepts What are the four main principles of Object-Oriented Programming (OOP)? Encapsulation: Bundling the data (variables) and the methods (functions) that manipulate the data into a single unit, or class, and restricting access to some of the object's components. Abstraction: Hiding the complex implementation details and showing only the essential features of the object. Inheritance: Creating new classes (derived classes) from existing classes (base classes) to promote code reuse. Polymorphism: The ability of different objects to respond in a unique way to the same message (method call). It can be achieved through method overriding (runtime polymorphism) or method overloading (compile-time polymorphism). What is a class and an object in OOP? Class: A blueprint or template for creating objects. It defines a datatype by bundling data and methods that work on the data into one single unit. Object: An instance of a class. It is a concrete entity based on a class, with...

Angular interview

Index What is Angular? What are the key features of Angular? Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide Deployment Guide What is Angular? Answer: Angular is an open-source front-end web framework developed and maintained by Google. It's a platform that allows developers to build dynamic, single-page web applications (SPAs) and progressive web apps (PWAs) with ease. Angular utilizes HTML as its template language and extends its syntax with directives to express the application's components more clearly. One of the distinctive features of Angular is its two-way data binding, which enables automatic synchronization of data between the model and the view. This means that changes made in the application's data reflect instantly in the UI, and vice versa. What are the key feature...