Try   HackMD

.NET Interview Questions

Introduction to .NET framework

.NET framework is developed by Microsoft which provides environment to run, debug and deploy code onto web services and applications by using tools and functionalities like libraries, classes and APIs. It supports different languages like C#, Cobol, VB, Perl etc.

Main components of .NET framework

.NET framework consists of 2 main components. They are:

  1. Common Language Runtime- It is an execution engine that runs the code and provides services that make the development process easier.
  2. Framework class Library- It has pre-defined methods and properties to implement common and complex functions that can be used by .NET applications.

How does .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 assembly file which has .dll or .exe file extension.
  • When .NET application runs, Common Language Runtime (CLR) takes the assembly file and converts the CIL into machine code with the help of Just In Time(JIT) compiler.
  • Now, this machine code can execute on the specific architecture of the computer it is running on.
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Scope of the .NET framework

It is used to create and run different form-based and web-based applications. Apps developed using .NET can run on many operating systems such as linux or windows, using different implementations of .NET. .NET is used by a lot of companies like Accenture, TerraCycle Inc. etc due to it's feature of scalable architecture.

.NET Interview Questions

.NET Basic Interview Questions

1. What is .NET framework?

.NET is the platform built by Microsoft which supports an object oriented approach. It is also used for running, debugging and deploying code onto web services and applications. It supports numerous languages like C#, Cobol, VB, Perl etc.

2. What is CTS?

  • CTS stands for Common Type System. It follows set of structured rules according to which a data type should be declared and used in the program code. It is used to describe all the data types that are going to be used in the application.
  • We can create our own classes and functions by following the rules in the CTS. It helps in calling the data type declared in one programming language by other programming languages.

3. Explain CLS.

Common Language Specification(CLS) helps the application developers to use the components that are inter-language compatible with certain rules that come with CLS. It also helps in reusing the code among all of the .NET compatible languages.

4. What is JIT?

JIT stands for Just In Time. It is a compiler which converts the intermediate code into the native language during the execution.

5. What is the difference between int and Int32?

There is no difference between int and Int32. Int32 is a type provided by .NET framework class whereas int is an alias name for Int32 in C# programming language.

6. Explain the differences between value type and reference type.

The main differences between value type and reference type are given below:

  • A Value Type holds the actual data directly within memory location and a reference type contains a pointer which consists of the address of another memory location that holds the actual data.
  • Value type stores its contents on the stack memory and reference type stores its contents on the heap memory.
  • Assigning value type variable to another variable will copy the value directly and assigning a reference variable to another doesn't copy the value, instead it creates a second copy of the reference.
  • Predefined datatypes, structures, enums are the examples of value types. Classes, Objects, Arrays, Indexers, Interfaces etc are the examples of reference types.

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

Managed code Unmanaged code
It is managed by CLR. It is not managed by CLR.
.NET framework is must for execution. Does not require .NET framework for the execution.
Memory management is done through garbage collection. Runtime environment takes care of memory management.

8. Explain MSIL.

  • MSIL is the Microsoft Intermediate Language, which provides instructions for calling methods, memory handling, storing and initializing values, exception handling and so on.
  • The instructions provided by MSIL are platform independent and are generated by the language-specific compiler from the source code. JIT compiler compiles the MSIL into machine code based on the requirement.

9. Differentiate between function and stored procedure.

Function Stored Procedure
It returns only one value. It returns one or more than one value.
Function has only input parameters. Can have both input and output parameters.
Does not support exception handling using try-catch block. Supports exception handling using try-catch block.
It can be called from a stored procedure. Stored procedure cannot be called from a function.

10. What is an assembly?

  • An assembly is a file that is automatically generated by the compiler which consists of collection of types and resources that are built to work together and form a logical unit of functionality. We can also say, assembly is a compiled code and logical unit of code.
  • Assemblies are implemented in the form of executable (.exe) or dynamic link library (.dll) files.

.NET Intermediate Interview Questions

1. Is ASP.NET different from ASP? If yes, explain how?

Yes, ASP.NET and ASP(Active Server Pages) both are different. Let's check how they are different from each other.

  1. ASP.NET uses .NET languages such as C# and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL). ASP uses VBScript. ASP code is interpreted during the execution.
  2. ASP.NET which is developed by Microsoft, is used to create dynamic web applications while ASP is a Microsoft's server-side technology used to create web pages.
  3. ASP.NET is fully object oriented but ASP is partially object oriented.
  4. ASP.NET has full XML Support for easy data exchange whereas ASP has no built-in support for XML.
  5. ASP.NET uses the ADO.NET technology to connect and work with databases. ASP uses a ADO technology.

2. Explain the different types of assembly.

Assemblies are classified into 2 types. They are:
1. Private Assembly:

  • It is accessible only to 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.

2. Shared or Public Assembly:

  • It can be shared by multiple applications.
  • Public assembly does not required to copy 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.
  • It is installed in the Global Assembly Cache(GAC).

3. What is a garbage collector?

Garbage collector frees the unused code objects in the memory. The memory heap is partitioned into 3 generations:

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

Collection of garbage refers to checking for objects in the generations of managed heap that are no longer being used by the application. It also performs the necessary operations to reclaim their memory. Garbage collector must perform a collection in order to free some memory space.

During the garbage collection process:

  • The list of live objects is recognized.
  • References are updated for the compacted objects.
  • The memory space occupied by dead objects are recollected. The remaining objects are moved to an older segment.

System.GC.Collect() method is used to perform garbage collection in .NET.

4. What is caching?

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

There are three types of caching:

  1. Page caching
  2. Data caching
  3. Fragment caching

5. Explain MVC.

MVC stands for Model View Controller. It is an architecture to build .NET applications. Following are three main logical components of MVC: the model, the view, and the controller.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Model: They hold data and its related logic. It handles the object storage and retrieval from the databases for an application. For example:

    • A Controller object will retrieve the employee information from the database.
    • It manipulates employee data and send back to the database or use it to render the same data.
  • View: View handles the UI part of an application. They get the information from the models for their display. For example, any employee view will include many components like text boxes, drop downs, etc.

  • Controller: They handle the user interactions, figure out the responses for the user input and also render the final output. For instance, the Employee controller will handle all the interactions and inputs from the Employee View and update the database using the Employee Model.

6. What is delegate in .NET?

  • A delegate is a .NET object which defines a method signature and it can pass a function as a parameter.
  • Delegate always points to a method that matches its specific signature. User can encapsulate the reference of a method in a delegate object.
  • When we pass deligate object in a program, it will call the referenced method. To create a custom event in a class, we can make use of delegate.

7. What is boxing and unboxing in .NET?

  • Boxing is the process of converting a value type into a reference type directly. Boxing is implicit.
  • Unboxing is the process where reference type is converted back into a value type. Unboxing is explicit.

An example is given below to demonstrate boxing and unboxing operations:

int a = 10;      // a value type
object o = a;     // boxing
int b = (int)o;   // unboxing

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

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

10. 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 kind of access modifiers like private, public, protected etc. are supported. Only public access modifier is supported.
It can contain static member. It does not contain static member.
Multiple inheritance cannot be achieved. Multiple inheritance is achieved.

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

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

  1. Stack: Stack is a stored value type which keeps track of each executing thread and its location. It is used for static memory allocation.
  2. Heap: Heap is a stored reference type which keeps track of the more precise objects or data. It is used for dynamic memory allocation.

12. Explain localization and globalization.

Localization- Localization is the process of customizing our application to behave as per the current culture and locale.

Globalization- Globalization is the process of designing the application so that it can be used by users from across the globe by supporting multiple languages.

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

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

  1. Connect Timeout
  2. Min Pool Size
  3. Max Pool Size
  4. Pooling

14. What are MDI and SDI?

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

15. Explain the different parts of an Assembly.

The different parts of an assembly are:

  • Manifest – It holds the information about the version of an assembly. It is also known as assembly metadata.
  • Type Metadata – It consists of binary information of the program.
  • MSIL – Microsoft Intermediate Language code.
  • Resources – List of related files.

.NET Advanced Interview Questions

1. What is an EXE and a DLL?

EXE and DLLs are assembly executable modules.

  • EXE - EXE is an executable file that runs the application for which it is designed. An EXE is produced when we build an application. Therefore the assemblies are loaded directly when we run an EXE. However, an EXE cannot be shared with the other applications.
  • DLL - Dynamic Link Library(DLL) is a library that consists of code that needs to be hidden. The code is encapsulated inside this library. An application can consist of many DLLs which can be shared with the other programs and applications.

2. 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 guests.

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

  1. Page_PreInit
  2. Page_Init
  3. Page_InitComplete
  4. Page_PreLoad
  5. Page_Load
  6. Page_LoadComplete
  7. Page_PreRender
  8. Render

4.Can we apply themes to ASP.NET applications?

Yes. By modifying the following code in the web.config file, we can apply themes to ASP.NET applications:

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

5. Differenciate between the user control and the custom control in the .NET framework.

User Control Custom control
It has Static Layout. It has Dynamic Layout.
A tightly coupled control access with respect to code and UI. A loosely coupled control access with respect to code and UI.
It doesn't support the toolbox. It supports the usage of the toolbox.
UI is fixed and cannot be changed in different projects. UI can be changed in different projects.
It defines a set of controls. It defines a single control.
Not very flexible like a Custom Control. More flexible.

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

7. What are security controls available on ASP.NET?

Following are the five security controls available on ASP.NET:

  • <asp: Login> : Provides a login capability that enables the users to enter their credentials with ID and password fields.
  • <asp: LoginName> : Used to display the user name who has logged-in.
  • <asp: LoginView> : Provides variety of views depending on the template that has been selected.
  • <asp: LoginStatus> : Used to check whether user is authenticated or not.
  • <asp: PasswordRecovery> : Sends an email to a user while resetting the password.

8. What is MIME in .NET?

  • 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 emails easily.
  • Servers insert the MIME header at the beginning of the web transmission to denote that it is a MIME transaction.
  • 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.

9. Explain different types of cookies available in ASP.NET?

Two types of cookies are available in ASP.NET. They are:

  1. Session Cookie: It resides on the client machine for a single session and is valid until the user logs out.
  2. Persistent Cookie: It resides on the user machine for a period specified for its expiry. It may be an hour, a day, a month or never.

10. What is the appSettings section in the web.config file?

We can use the appSettings block in the web.config file, if we want to set the user-defined values for the whole applications. Example code given below will make use of ConnectionString for the database connection throughout the project:

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

Conclusion

The scope of .NET is wide. It is a full-stack framework used to build entire large enterprise-scale and scalable software applications. .NET is fast, flexible, modern and friendly and goes along well with other technologies which is why it is very popular among software developers.

References

Multiple choice questions

1. int keyword refers to which .Net type?

  • a. System.Int32
  • b. System.Int8
  • c. System.Int16
  • d. System.Int64
  • Answer: a. System.Int32

2. Boxing allows the user to convert what?

  • a. integer type to double
  • b. value type to a reference type
  • c. reference type to a value type
  • d. double type to integer
  • Answer: b. value type to a reference type

3. An Event has ____ as default return type.

  • a. No return type for events
  • b. Integer
  • c. String
  • d. Double
  • Answer: c. String

4. If the exception does not occur, will finally block get executed?

  • a. There is no such block as finally
  • b. Yes
  • c. No
  • d. Both catch and finally block will be executed.
  • Answer: b. Yes

5. If a variable is declared inside a method, then it is called as _______

  • a. Static
  • b. Serial
  • c. Local
  • d. Private
  • Answer: c. Local

6. Runtime environment provided by .NET is called as _______

  • a. RMT
  • b. CLR
  • c. RC
  • d. RCT
  • Answer: b. CLR

7. In which file .Net assembly’s metadata is stored?

  • a. manifest
  • b. .dll
  • c. .exe
  • d. core
  • Answer: a. manifest

8. Common Type System(CTS) can manage _______

  • a. Value types
  • b. All data types in .net
  • c. Reference types
  • d. Communication between multiple languages
  • Answer: d. Communication between multiple languages

9. Specify root namespace used for fundamental types in .Net framework.

  • a. System.Web
  • b. System.IO
  • c. System.Object
  • d. System.File
  • Answer: c. System.Object

10. Which method is used to force garbage collection to run?

  • a. GC.Run() method
  • b. GC.Collection() method
  • c. GC.Finalize() method
  • d. GC.Collect() method
  • Answer: d. GC.Collect() method

11. What is the functionality of Response.Output.Write()?

  • a. Response.Output.Write() allows you to buffer output
  • b. Response.Output.Write() allows you to flush output
  • c. Response.Output.Write() allows you to write formatted output
  • d. Response.Output.Write() allows you to stream output
  • Answer: d. Response.Output.Write() allows you to stream output

12. Identify the type of JIT.

  • a. Pre-JIT
  • b. Econo-JT
  • c. Normal-JIT
  • d. All of the above
  • Answer: d. All of the above

13. Global Assembly Cache(GAC) stores

  • a. Global dlls
  • b. .NET assemblies which are shared between multiple applications
  • c. Cache application data
  • d. None of the above
  • Answer: b. .NET assemblies which are shared between multiple applications