Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Top 50 .Net interview Questions and Answers

.NET framework is developed by Microsoft that primarily runs on windows, which is used for building, deploying and running applications that use .NET technologies like, desktop and web applications etc. So, this Blog will help you to clear .NET interview and to brush up your knowledge before the interview.

Let’s start –

  1. What is the .NET framework?

The .NET framework supports an object-oriented approach that is used for building applications on windows. It supports various languages like C#, VB, Cobol, Perl, .NET, etc. It has a wide variety of tools and functionalities like class, library and APIs that are used to build, deploy and run web services and different applications.

2. What are the different components of .NET?

Following are the components of .NET

  • Common Language run-time
  • Application Domain
  • Common Type System
  • .NET Class Library
  • .NET Framework
  • Profiling

3. What is CLR?

The Common Language Runtime (CLR) - ppt download
what is CLR

CLR stands for common language run-time, it is an important component of the .NET framework. We can use CLR as a building block of various applications and provides a secure execution environment for applications.

Whenever an application written in C# is compiled, the code is converted into an intermediate language. After this, the code is targeted to CLR which then performs several operations like memory management, security checks, loading assemblies, and thread management.

4. What do you know about CTS?

CTS stands for Common Type System. It follows certain rules according to which a data type should be declared and used in the program code. CTS also describes the data types that are going to be used in the application. We can even make our own classes and functions following the rules in the CTS, it helps in calling the data type declared in one program language by other programming languages.

5. Explain CLS?

Common language specification helps the developers to use the components that are inter-language compatible with certain rules that come with CLS. It then helps in reusing the code in other .NET compatible languages.

6. What do you know about JIT?

JIT (Just In Time) Meaning, Importance & Example | MBA Skool
JIT

JIT is a compiler which stands for Just In Time. It is used to convert the intermediate code into the native language. During the execution, the intermediate code is converted into the native language.

7. What is the difference between Response.Redirect and Server.Transfer?

Response.Redirect basically redirects the user’s browser to another page or site. The history of the user’s browser is updated to reflect the new address as well. It also performs a trip back to the client where the client’s browser is redirected to the new page.

Whereas, Server.Transfer transfers from one page to the other without making any round-trip back to the client’s browser. The history does not get updated in the case of Server.Transfer.

8. Explain the difference between a class and an object?

ClassObject
Class is the definition of an objectAn object is an instance of a class.
It is a template of the objectA class does not become an object unless instantiated
It describes all the methods, properties, etcAn object is used to access all those properties from the class.

9. What is the difference between managed and unmanaged code?

Managed codeUnmanaged code
Managed code is managed by CLR
Any code that is not managed by CLR
.NET framework is necessary to execute managed code managed code
Independent of .NET framework
CLR manages memory management through garbage collectionOwn runtime environment for compilation and execution

10. What is BCL?

  • BCL is a base class library of classes, interfaces and value types
  • It is the foundation of .NET framework applications, components, and controls
  • Encapsulates a huge number of common functions and make them easily available for the developers
  • It provides functionality like threading, input/output, security, diagnostics, resources, globalization, etc.
  • Also serves the purpose of interaction between user and runtime
  • It also provides namespaces that are used very frequently. for eg: system, system.Activities, etc.

11. What is the difference between namespace and assembly?

difference between namespace and assembly?

An assembly is a physical grouping of logical units whereas namespace groups classes. Also, a namespace can span multiple assemblies as well.

12. What is LINQ?

It is an acronym for Language integrated query which was introduced with visual studio 2008. LINQ is a set of features that extend query capabilities to the .NET framework language syntax that allows data manipulation irrespective of the data source. LINQ bridges the gap between the world of objects and the world of data.

13. What is MSIL?

MSIL is the Microsoft Intermediate Language, it provides instructions for calling methods, storing and initializing values, memory handling, exception handling and so on. All the .NET codes are first compiled to Intermediate Language.

14. Explain the different parts of the assembly?

Following are the different parts of assembly:

  • Manifest: It has the information about the version of the assembly.
  • Type Metadata: Contains the binary information of the program
  • MSIL: Microsoft Intermediate Language Code
  • Resources: List of related files

15. What is .NET Core SDK?

.NET Core SDK is a set of tools and libraries that allows the developer to create a .NET application and library for .NET 5 (also .NET Core) and later versions. It includes the .NET CLI for building applications, .NET libraries and runtime for the purpose of building and running apps, and the dotnet.exe(dotnet executable) that runs CLI commands and runs an application.

16. How do you prevent a class from being inherited?

In C#, we can use the sealed keyword to prevent a class from being inherited.

17. What are the different types of assemblies?

There are two types of assemblies:

  • Private Assembly: It is accessible only to the application, it is installed in the installation directory of the application.
  • Shared Assembly: It can be shared by multiple applications, it is installed in the GAC.

18. What is the difference between custom and user control?

Difference between User Control and Custom Control? - Stack Overflow
difference between custom and user control
Custom ControlUser Control
Derives from controlDerives from UserControl
Dynamic LayoutStatic Layout
Defines a single controlDefines a set of con
It has full toolbox supportCannot be added to the toolbox
Loosely coupled controlTightly coupled control

19. What are MDI and SDI?

  • MDI( Multiple Document Interface): An MDI lets you open multiple windows, it will have one parent window and as many child windows. The components are shared from the parent window like menubar, toolbar, etc.
  • SDI( Single Document Interface): It opens each document in a separate window. Each window has its own components like menubar, toolbar, etc. Therefore it is not constrained to the parent window.

20. What is a garbage collector?

Garbage collector feature in .NET frees the unused code objects in the memory. The memory head is divided into 3 generations:

  • Generation 0: It stores short-lived objects.
  • Generation 1: This is for medium-lived objects.
  • Generation 2: It stores long-lived objects.

Collection of garbage refers to the collection of objects stored in the generations.

21. Explain MVC?

MVC stands for model view controller which is an architecture to build .NET applications.

  • Model: They are the logical part of any application that handles the object storage and retrieval from the databases for an application.
  • View: View handles the UI part of an application. They get the information from the models for their display.
  • Controller: They handle the user interactions, figure out the responses for the user input and also render the view that is required for the user interaction.

22. What is caching?

Caching

Caching simply means storing the data temporarily in the memory so that the data can be accessed from the memory instead of searching for it in the original location. It increases the efficiency of the application and also increases its speed.

Following are the types of caching:

  • Page caching
  • Data caching
  • Fragment caching

23. What is the application domain?

ASP.NET introduces a concept of application domain or AppDomain which is like a lightweight process that acts like both container and boundary. The .NET run-time uses the AppDomain as a container for data and code. The CLR allows multiple .NET applications to run in a single AppDomain.

24. What is delegate in .NET?

A delegate in .NET is similar to a function pointer in other programming languages like C or C++. A delegate allows the user to encapsulate the reference of a method in a delegate object. A delegate object can then be passed in a program, which will call the referenced method. We can even use a delegate method to create a custom event in a class.

25. What is CAS?

CAS stands for code access security, CAS is a part of a security model that prevents unauthorized access to the resources. It also enables the users to set permissions for the code. CLR then executes the code depending upon the permissions.

CAS can only be used for managed code. If an assembly uses CAS it is treated as partially trusted. Although it goes through checks each time an assembly tries to access the resources.

26. Explain localization and globalization?

Globalization, Localization and Statistics Mustafa Dinc, PhD Prepared for  the session “Measuring globalization - do we have the right numbers?” of  the. - ppt download
localization and globalization
LocalizationGlobalization
It means changing the already globalized application to cater to a specific language or culture.Globalization is the process of developing applications to support multiple languages.
Microsoft.Extensions.Localization is used to localize the application content.Existing applications can also be converted to support multiple languages.

27. What are EXE and DLL?

EXE and DLL are assembly executable modules.

  • EXE: It is an executable file that runs the application for which it is designed. When we build an application, an exe file is generated. Therefore the assemblies are loaded directly when we run an exe. But an exe file cannot be shared with other applications.
  • DLL: It stands for dynamic link library that consists of code that needs to be hidden. The code is encapsulated in this library, an application can have many DLLs and can also be shared with other applications.

28. What are Universal Windows Platform(UWP) Apps in .Net Core?

Universal Windows Platform(UWP) is one of the methods used to create client applications for Windows. UWP apps will make use of WinRT APIs for providing powerful UI as well as features of advanced asynchronous that are ideal for devices with internet connections.

Features of UWP apps:

  • Secure: UWP apps will specify which resources of device and data are accessed by them.
  • It is possible to use a common API on all devices(that run on Windows 10).
  • It enables us to use the specific capabilities of the device and adapt the user interface(UI) to different device screen sizes, DPI(Dots Per Inches), and resolutions.
  • It is available on the Microsoft Store on all or specified devices that run on Windows 10.
  • We can install and uninstall these apps without any risk to the machine/incurring “machine rot”.
  • Engaging: It uses live tiles, user activities, and push notifications, that interact with the Timeline of Windows as well as with Cortana’s Pick Up Where I Left Off, for engaging users.
  • It can be programmable in C++, C#, Javascript, and Visual Basic. For UI, you can make use of WinUI, HTML, XAML, or DirectX.

29. What is the difference between function and stored procedure?

FunctionStored Procedure
Must return a single value
Always used to perform a specific task
It can only have the input parameter
It can have both input and output parameters
Exception handling is not possible using a try-catch blockException handling can be done using a try-catch block
A stored procedure cannot be called from a function
A function can be called from a procedure

30. How is it possible for .NET to support many languages?

The .NET language code is compiled to Microsoft Intermediate Language (MSIL). The generated code is called managed code. This managed code is run in .NET environment. So after compilation the language is not a barrier and the code can call or use function of another language also.

31. What is the state management in ASP.NET?

State management is a technique that is used to manage a state of an object on different request. It is very important to manage state in any web application. There are two types of state management systems in ASP.NET.

  • Client side state management
  • Server side state management

32. What is the difference between int and int32?

There is no difference between int and int32. System. Int is an alias name for System.Int32 which is a .Net Class.

33. What are differences between function and stored procedure in .Net programming language?

The difference between function and stored procedure:

  • Function returns only one value but procedure can return one or more than one value.
  • Function can be used in select statements but procedure cannot be used.
  • Function has only input parameters while Procedure can have an input and output parameters.
  • Exceptions can be handled by try catch block in procedures but that is not possible in function.

34. What is meant by Managed and Unmanaged code?

  • The code that is managed by the CLR is called Managed code. This code runs inside the CLR. Hence, it is necessary to install the .Net framework in order to execute the managed code. CLR manages the memory through garbage collection and also uses the other features like CAS and CTS for efficient management of the code.
  • Unmanaged code is any code that does not depend on CLR for execution. It means it is developed by any other language independent of .Net framework. It uses its own runtime environment for compiling and execution.
  • Though it is not running inside the CLR, the unmanaged code will work properly if all the other parameters are correctly followed.

35. Explain role-based security in .NET?

Role-based security is used to implement security measures in .NET, based on the roles assigned to the users in the organization. In the organization, authorization of users is done based on their roles.

For example, windows have role-based access like administrators, users, and guest.

36. What is the order of the events in a page life cycle?

There are eight events as given below that take place in an order to successfully render a page:

  • Page_PreInit
  • Page_Init
  • Page_InitComplete
  • Page_PreLoad
  • Page_Load
  • Page_LoadComplete
  • Page_PreRender
  • Render

37. What is cross-page posting?

Whenever we click on a submit button on a webpage, the data is stored on the same page. But if the data is stored on a different page and linked to the current one, then it is known as a cross-page posting. Cross-page posting is achieved by POSTBACKURL property.

To get the values that are posted on this page to which the page has been posted, the FindControl method can be used.

38. What is the meaning of CAS in .NET?

Code Access Security(CAS) is necessary to prevent unauthorized access to programs and resources in the runtime. It is designed to solve the issues faced when obtaining code from external sources, which may contain bugs and vulnerabilities that make the user’s system vulnerable.

CAS gives limited access to code to perform only certain operations instead of providing all at a given point in time. CAS constructs a part of the native .NET security architecture.

39. What are the types of memories supported in the .NET framework?

Two types of memories are present in .NET. They are:

Stack: Stack is a stored-value type that keeps track of each executing thread and its location. It is used for static memory allocation.

Heap: Heap is a stored reference type that keeps track of the more precise objects or data. It is used for dynamic memory allocation

40. What are the parameters that control the connection pooling behaviors?

There are 4 parameters that control the connection pooling behaviours. They are:

  • Connect Timeout
  • Min Pool Size
  • Max Pool Size
  • Pooling

41. What are C# and F#?

C# is a general-purpose and object-oriented programming language from Microsoft that runs on the .NET platform. It is designed for CLI(Common Language Infrastructure), which has executable code and a runtime environment that allows for the usage of different high-level languages on various computer platforms and architectures. It is mainly used for developing web applications, desktop applications, mobile applications, database applications, games, etc.

F# is an open-source, functional-first, object-oriented and, cross-platform programming language that runs on a .NET platform and is used for writing robust, succinct, and performant code. We can say that F# is data-oriented because here code involves transforming data with functions. It is mainly used in making scientific models, artificial intelligence research work, mathematical problem solving, financial modelling, GUI games, CPU design, compiler programming, etc.

42. What is Zero Garbage Collectors?

xZero Garbage Collectors allows you for object allocation as this is required by the Execution Engine. Created objects will not get deleted automatically and theoretically, no longer required memory is never reclaimed.

There are two main uses of Zero Garbage Collectors. They are:

  • Using this, you can develop your own Garbage Collection mechanism. It provides the necessary functionalities for properly doing the runtime work.
  • It can be used in special use cases like very short living applications or almost no memory allocation(concepts such as No-alloc or Zero-alloc programming). In these cases, Garbage Collection overhead is not required and it is better to get rid of it.

43. What is CoreFx?

CoreFX is the set of class library implementations for .NET Core. It includes collection types, console, file systems, XML, JSON, async, etc. It is platform-neutral code, which means it can be shared across all platforms. Platform-neutral code is implemented in the form of a single portable assembly that can be used on all platforms.

44. What is the use of generating SQL scripts in the .NET core?

It’s useful to generate a SQL script, whenever you are trying to debug or deploy your migrations to a production database. The SQL script can be used in the future for reviewing the accuracy of data and tuned to fit the production database requirement.

45. Explain about types of Common Type System(CTS).

Common Type System(CTS) standardizes all the datatypes that can be used by different programming languages under the .NET framework.

CTS has two types. They are:

  1. Value Types: They contain the values that are stored on a stack or allocated inline within a structure. They are divided into
  • Built-in Value Types – It includes primitive data types such as Boolean, Byte, Char, Int32, etc.
  • User-defined Value Types – These are defined by the user in the source code. It can be enumeration or structure.
  • Enumerations – It is a set of enumerated values stored in the form of numeric type and are represented by labels.
  • Structures – It defines both data(fields of the structure) and the methods(operations performed on that data) of the structure. In .NET, all primitive data types like Boolean, Byte, Char, DateTime, Decimal, etc., are defined as structures.

2. Reference Types: It Stores a reference to the memory address of a value and is stored on the heap. They are divided into:

  • Interface types – It is used to implement functionalities such as testing for equality, comparing and sorting, etc.
  • Pointer types – It is a variable that holds the address of another variable.
  • Self-describing types – It is a data type that gives information about themselves for the sake of garbage collectors. It includes arrays(collection of variables with the same datatype stored under a single name) and class types(they define the operations like methods, properties, or events that are performed by an object and the data that the object contains) like user-defined classes, boxed value types, and delegates(used for event handlers and callback functions).

46. What is Transfer-encoding?

Transfer-encoding is used for transferring the payload body(information part of the data sent in the HTTP message body) to the user. It is a hop-by-hop header, that is applied not to a resource itself, but to a message between two nodes. Each multi-node connection segment can make use of various Transfer-encoding values.

Transfer-encoding is set to “Chunked” specifying that Hypertext Transfer Protocol’s mechanism of Chunked encoding data transfer is initiated in which data will be sent in a form of a series of “chunks”. This is helpful when the amount of data sent to the client is larger and the total size of the response will not be known until the completion of request processing.

47. What are Universal Windows Platform(UWP) Apps in .Net Core?

Universal Windows Platform(UWP) is one of the methods used to create client applications for Windows. UWP apps will make use of WinRT APIs for providing powerful UI as well as features of advanced asynchronous that are ideal for devices with internet connections.

Features of UWP apps:

  • Secure: UWP apps will specify which resources of device and data are accessed by them.
  • It is possible to use a common API on all devices(that run on Windows 10).
  • It enables us to use the specific capabilities of the device and adapt the user interface(UI) to different device screen sizes, DPI(Dots Per Inches), and resolutions.
  • It is available on the Microsoft Store on all or specified devices that run on Windows 10.
  • We can install and uninstall these apps without any risk to the machine/incurring “machine rot”.
  • Engaging: It uses live tiles, user activities, and push notifications, that interact with the Timeline of Windows as well as with Cortana’s Pick Up Where I Left Off, for engaging users.
  • It can be programmable in C++, C#, Javascript, and Visual Basic. For UI, you can make use of WinUI, HTML, XAML, or DirectX.

48. What is middleware in .NET core?

Middleware is software assembled into an application pipeline for request and response handling.

Each component will choose whether the request should be passed to the next component within the pipeline, also it can carry out work before and after the next component within the pipeline.
For example, we can have a middleware component for user authentication, another middleware for handling errors, and one more middleware for serving static files like JavaScript files, images, CSS files, etc.

It can be built-in into the .NET Core framework, which can be added through NuGet packages. These middleware components are built as part of the configure method’s application startup class.

In the ASP.NET Core application, these Configure methods will set up a request processing pipeline. It contains a sequence of request delegates that are called one after another.

Normally, each middleware will handle the incoming requests and passes the response to the next middleware for processing. A middleware component can take the decision of not calling the next middleware in the pipeline.

This process is known as short-circuiting the pipeline or terminating the request pipeline. This process is very helpful as it avoids unnecessary work. For example, if the request is made for a static file such as a CSS file, image, or JavaScript file, etc., these static files middleware can process and serve the request and thus short-circuit the remaining pipeline.

49. What is MEF?

The MEF(Managed Extensibility Framework) is a library that is useful for developing extensible and lightweight applications. It permits application developers for using extensions without the need for configuration. It also allows extension developers for easier code encapsulation and thus avoiding fragile hard dependencies. MEF will let you reuse the extensions within applications, as well as across the applications. It is an integral part of the .NET Framework 4. It improves the maintainability, flexibility, and testability of large applications.

50. What is CoreRT?

  • CoreRT is the native runtime for the compilation of .NET natively ahead of time and it is a part of the new .NET Native (as announced in April 2014).
  • It is not a virtual machine and it does not have the facility of generating and running the code on the fly as it doesn’t include a JIT. It has the ability for RTTI(run-time type identification) and reflection, along with that it has GC(Garbage Collector).
  • The type system of the CoreRT is designed in such a way that metadata for reflection is not at all required. This feature enables to have an AOT toolchain that can link away unused metadata and can identify unused application code.
Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x