top of page

Top .NET Interview Questions and Answers



Q-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.


Q-2. How does the .NET framework work?

  • .NET framework-based applications that are written in supportive languages like C#, F#, or Visual basic are compiled to Common Intermediate Language (CIL).

  • Compiled code is stored in the form of an assembly file that has a .dll or .exe file extension.

  • When the .NET application runs, Common Language Runtime (CLR) takes the assembly file and converts the CIL into machine code with the help of the Just In Time(JIT) compiler.

  • Now, this machine code can execute on the specific architecture of the computer it is running on.



Q-3: 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


Q-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.


Q-5: 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.


Q-6: 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.


Q-7: What do you know about 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.


Q-8: 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.


Q-9: 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.


Q-10: What is the 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.


Q-11: 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.


Q-12: 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.


Q-13: From which base class all web Forms are inherited?

All web forms are inherited from page class.

Want to upskill yourself to get ahead in your career? Check out this video

Q-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

Q-15: What are the different types of constructors in c#? Following are the types of constructors in C#:

  • Default Constructor

  • Parameterized constructor

  • Copy Constructor

  • Static Constructor

  • Private Constructor


Q-16: 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. We need to copy this private assembly, separately in all application folders where we want to use that assembly. Without copying, we cannot access the private assembly.

It requires to be installed in the installation directory of the application.


Shared or Public Assembly: It can be shared by multiple applications, it is installed in the GAC. Public assembly does not require copying separately into all application folders. Only one copy of public assembly is required at the system level, we can use the same copy by multiple applications.


Q-17: 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.

Q-18: What is 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


Q-19: 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. Q-20: 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.

Q-21: Explain localization and globalization. Localization: It means changing the already globalized application to cater to a specific language or culture. Microsoft.Extensions.Localization is used to localize the application content


Globalization: Globalization is the process of developing applications to support multiple languages.Existing applications can also be converted to support multiple languages.


Q-22: 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.


Q-23: What are the different validators in ASP.NET?

  • Client-side validation – When the validation takes place on the client-side browser, it is called client-side validation. Usually, JavaScript is used for client-side validation.

  • Server-side validation – When the validation takes place on the server then it is called server-side validation. Server-side validation is considered as a secure form of validation because even if the user bypasses the client-side validation we can still catch it in server-side validation.


Q-24: List the events in the page life cycle. Following are the events in the page life cycle:

  • Page_PreInit

  • Page_Init

  • Page_InitComplete

  • Page_PreLoad

  • Page_Load

  • Page_LoadComplete

  • Page_PreRender

  • Render


Q-25: What is the code to send an email from an ASP.NET application?

mail message = new mail();
message.From = "abc@gmail.com";
message.To = "xyz@gmail.com";
message.Subject = "Test";
message.Body = "hello";
 
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(message);

Q-26: What are the event handlers that we have for the Global.asax file?

  • Application Events:

Application_Start, Application_End, Application_AcquireRequestState, Application_AuthenticateRequest, Application_AuthorizeRequest, Application_BeginRequest, Application_Disposed, Application_EndRequest, Application_Error, Application_PostRequestHandlerExecute, Application_PreRequestHandlerExecute, Application_PreSendRequestContent, Application_PreSendRequestHeaders, Application_ReleaseRequestState, Application_ResolveRequestCache, Application_UpdateRequestCache

  • Session Events:

Session_Start, Session_End


Q-27: Explain role-based security. Role-based security is used to implement security measures based on the role assigned to the users in the organization. Then we can authorize users based on their roles in the organization. For example, windows have role-based access like user, administrators, and guests.

Q-28: What is cross-page posting? Whenever we click on a submit button on a page, the data is stored on the same page. But if the data is stored on a different page, it is known as a cross-page posting. Cross-page posting can be achieved by POSTBACKURL property which causes the postback. FindControl method can be used to get the values that are posted on this page to which the page has been posted.

Q-29: How can we apply themes to an ASP.NET application? We can use the web.config file to specify the themes

<cofiguration>
<system.web>
<pages theme="windows"/>
</system.web>
</configuration>

Q-30: Explain passport authentication. During the passport authentication, it first checks the passport authentication cookie, if the cookie is not available the application redirects to the passport sign on page. Passport service then authenticates the details of the user on the sign on page and if they are valid, stores them on the client machine and then redirects the user to the requested page.

Q-31: What are ASP.NET security controls?

  • <asp: Login>: Provides a login capability that enables the users to enter their credentials.

  • <asp: LoginName>: Allows you to display the name of the logged-in user.

  • <asp: LoginStatus>: Displays if the user is authenticated or not.

  • <asp: LoginView>: provides various login views depending on the template that has been selected.

  • <asp: PasswordRecovery>: Emails the users the lost passwords.


Q-32: List all the templates of the Repeater control.

  • ItemTemplate

  • AlternatingItemTemplate

  • SeparatorTemplate

  • HeaderTemplate

  • FooterTemplate


Q-33: What is the appSettings section in the web.config file? If we want to set the user-defined values for the whole applications, we can use the appSettings block in the web.config file. For example the code below uses the ConnectionString throughout the project for the database connection:

<em><configuration>
<appsettings>
<add key= "ConnectionString" value="server=local; pwd=password; database=default" />
</appSettings></em>

Q-34: What is MIME? MIME stands for multipurpose internet mail extensions, it is the extension of the e-mail protocol which lets users use the protocol to exchange files over the internet. Servers insert the MIME header at the beginning of the web transmission. Then the clients use this header to select an appropriate ‘player’ for the type of data that the header indicates. Some of these players are built into the web browser.

Q-35: What is HTTP Handler? Every request into an ASP.NET application is handled by a specialized component called HTTP handler. It is the most important component for handling ASP.NET application requests. It uses different handlers to serve different files. The handler for web page creates the page and control objects, runs your code and then renders the final HTML.

Following are the default HTTP handlers for ASP.NET:

  • Page Handler(.aspx): Handles web pages

  • User Control Handler(.ascx): It handles web user control pages

  • Web Service Handler(.asmx): Handles web service pages

  • Trace Handler(trace.axd): It handles trace functionality


Q-36: What are the different types of cookies in ASP.NET?

  • Session Cookie: It resides on the client machine for a single session until the user logs out.

  • Persistent Cookie: Resides on the user machine for a period specified for its expiry. It may be an hour, a month or never.


Q-37: What is the difference between ExecuteScalar and ExecuteNonQuery?

ExecuteScalar:

  • Returns the output value

  • Used for fetching a single value

  • Does not return the number of affected rows


ExecuteNonQuery:

  • Does not return any value

  • Used to execute insert and update statements

  • Returns the number of affected rows.


Q-38. What is the use of manifest in the .NET framework?

Manifest stores the metadata of the assembly. It contains metadata which is required for many things as given below:

  • Assembly version information.

  • Scope checking of the assembly.

  • Reference validation to classes.

  • Security identification


Q-39. 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.


Q-40. What is the difference between an abstract class and an interface?

Abstract Class

Interface

Used to declare properties, events, methods, and fields as well

Fields cannot be declared using interfaces.

Provides the partial implementation of functionalities that must be implemented by inheriting classes.

Used to declare the behavior of an implementing class.

Different kinds of access modifiers like private, public, protected, etc. are supported.

Only public access modifier is supported.

It can contain static members.

It does not contain static members.

Multiple inheritances cannot be achieved.

Multiple inheritances are achieved.



The Tech Platform

0 comments
bottom of page