Top most important .Net interview questions and answers by Experts:
Here is a list of Top most important .Net interview questions and answers by Experts.If you want to download .Net interview questions pdf free ,you can register with RVH techguru. Our experts prepared these .Net interview questions to accommodate freshers level to most experienced level technical interviews.
If you want to become an expert in .Net ,Register for .Net online training here.
1) What are the advantages of .Net?
• Good Design
• Object-Oriented Programming – Using C# and .NET which are based on object-oriented Concepts.
• Language Independence – All the languages which are supported by .Net (VB.NET, C#, J#, and managed C++) are compiled into common Intermediate Language (IL). So IL makes sure that languages are interoperable.
• Efficient Data Access – ADO.NET provides fast and efficient way to access RDBMS, file system etc.
• Code Sharing – To share code between applications, a new concept called assembly is introduced. Assemblies supports versioning.
• Improved Security
• Support Dynamic Web Pages – Using ASP.NET
• Support for Web Services
2) What is .Net Framework ?
The .NET framework is a programming framework from Microsoft. Developers can use .Net Framework to develop applications, install and run the application on Windows operating systems.
3) What is MS-IL (Microsoft Intermediate Language) ?
When a program is complied in .Net, the source code will be converted into an intermediate language called Microsoft Intermediate Language (MS-IL). This is done by Just-In time Compiler (JIT). The dot net framework is built in such a way that the code is Just-In time complied, which means that it get complied when it is called rather than compiling entire code at the start up. A portion of the code will get complied only once and it will exist till the application exit. This will have a significant improvement in performance since the entire section of the code won’t get executed in most cases.
4) What is Common Language Runtime (CLR) ?
Common Language Runtime or CLR is the run-time execution environment of .Net Framework. Converting MS-IL into platform or OS specific code is done by the CLR. Currently, .Net programs will run only on windows.
5) What is Common Type System (CTS) ?
.Net uses Common Type System (CTS) for Language Interoperability. CTS defines the predefined data types that are available in IL, so that all languages that target the .NET framework will produce the compiled code that is ultimately based on these types. CTS ensures that a data type defined in a VB.net will be understood by C#. For example, VB.Net uses “Integer” to define the data type Integer. C# uses “int” to define the data type Integer. When VB.Net code is compiled, it will convert the Integer to Int32. Since C# refers Int to Int32, VB.Net code will be understood by C#.
6) What is Common Language Specification (CLS) ?
Common Language Specification (CLS) is used for Language Interoperability in tandem with CTS to ensure the interoperability of the languages. CLS defines a set of minimum standards that all compilers targeting dot net must support. For example, VB.Net is not case sensitive. So attribute “EmployeeName” and “employeename” is considered same. But C# is case sensitive. So for language interoperability, C# doesn’t allow two variables which differ only in case.
7) What is Garbage Collector ?
Garbage Collector is used in dot net Framework for memory management. While running an application, applications make a request for memory for its internal use. Framework allocates memory from the heap. Once the process is completed, allocated memory needs to be reclaimed for future use. The process of reclaiming unused memory is taken care by the Garbage Collector.
8) How to invoke garbage collector programmatically ?
To call garbage collector from a program, use code “ GC.Collect(); “
9) What is a Managed Code ?
Managed code is code that can be executed and managed by .NET Framework Common Language Runtime. All codes based on the intermediate language(EL) executes as managed code.
10) What is an Assembly ?
Assemblies are self-describing logical unit which consists of one or more files targeted at dot net. An assembly can be stored across single file such as a single DLL or EXE that includes metadata, or it can be stored in multiple files. For example, resource files like meta data, DLL’s, and an EXE. Assemblies support versioning.
11) What is Assembly Manifest ?
Part of the assembly which contains assembly meta data that describes the assembly itself is known as manifest. Assembly manifest contains Assembly Name, Version Number, Culture, Strong name, List of files inside the assembly and Reference information.
12) What are the different types of Assembly ?
The two types of Assemblies are Shared and Private.
13) What is a Private Assembly ?
Private Assemblies are intended to be used by the program for which it is made for. Reason behind this is that, the application will only load private assemblies that are located in the same folder or in the sub folder of the main executable.
14) What is Shared Assembly ?
Shared Assemblies contain Common Libraries which are intended to be used by multiple applications. While making shared assemblies, name collisions and overwriting existing assemblies need to be taken care. Name Collisions can be taken care by strong name. Global assembly cache can be used to avoid assembly overwriting.
15) How to view Assembly information ?
By using Ildasm.exe, which is an MSIL Disassembler one can view attributes, references to other modules and assemblies.
16) Where is the assembly version information stored ?
In the Manifest.
17) What is NameSpace ?
A namespace is a logical grouping of related classes and types. Every class should have a NameSpace.
18) What is the Difference between NameSpace and Assembly ?
Namespace:
• Forms the logical boundary for a Group of classes.
• It is a Collection of names where each name is Unique.
• The namespace must be specified in Project Properties.
Assembly:
• Assemblies are Self-Describing
• It is an Output Unit. It is a unit of deployment and is used for versioning. Assemblies contain MSIL code.
19) What is Global Assembly Cache (GAC) ?
While using shared assemblies, to avoid Assembly being overwritten by a different version of the same assembly, shared assemblies are placed in a special directory subtree of the file system known as the global assembly cache (GAC). Placing shared assemblies can only be done by a special .Net Utilities.
20) Explain the concept of strong names ?
While using shared assemblies, in order to avoid name collisions strong names are used. Strong Names are based on private key cryptography, ie. private assemblies are simply given the same name as their main file name.
21) How to add and remove a assembly from GAC?
To install assembly in Cache, use Gacutil. To run Gacutil, goto “Visual Studio Command Prompt” and type “gacutil -i <assembly_name>”, where (assembly_name) is the DLL name of the project. To uninstall assembly, type gacutil –u <assembly name> in Visual Studio Command Prompt.
22) What is Reflection?
Reflection is used to dynamically load a class, create object and invoke methods at runtime. It can also be used to read its own meta data to find assemblies, modules and type information at runtime.
23) What is Delay signing ?
To create a strong named assembly and to make sure that this assembly can used by someone else, we partially build this assembly by providing a Public Key. We write this Public Key in the AssemblyInfo.vb OR .cs file. We also add an attribute by the name <Assembly:AssemblyDelaySignAttribute(true)> to the assembly info file. This makes it sure that when we build the assembly, it would be containing the information only about the public key before we deliver it to our clients. This is a partial strong named assembly that we have created, and hence it is called Delayed Assembly.
24) What are the different type of JIT’s ?
Different Types of JIT are
1) Pre-JIT – Complies complete source code into native code at the time of deployment.
2) Econo-JIT – Complies methods that are called at runtime.
3) Normal-JIT – Complies methods that are called at runtime and get stored in cache. Next time when the same method is called, it will be taken from cache.
25) What are Value types and Reference types ?
There are two types of data types in .Net, Value types and Reference types. Value types are stored in stack part of the memory. Reference type are stored in managed heap. Let have a look at the example for better understanding.
Int iCount = 0; \\ Value Type
int NewiCount = iCount; \\ Reference Type
26) Explain the concept of Boxing and Unboxing ?
Converting a value type to reference type is called Boxing. Converting a reference type to value type is called Unboxing.
27) What’s the difference between System exceptions and Application exceptions?
System exceptions are common exceptions thrown by the CLR of .Net Framework. Application exceptions can be user defined exceptions thrown by the application.
28) What is CODE Access security?
CODE Access security is a security model that let us grant or deny execution permissions to an assembly according to its “properties,” called evidence, such as its strong name or publisher
29) What is a satellite assembly?
A satellite assembly are used when multilingual (UI) application are created. Satellite assembly is a compiled library that contains localized resources which provides us with the capability of designing and deploying solutions to multiple cultures, rather than hard coding texts, bitmaps etc
30) How to prevent my .NET DLL to be decompiled ?
We can prevent .NET DLL to be decompiled upto an extent by Obfuscate Source code, asymmetric encryption and encrypted w32 wrapper application.
31) What is Native Image Generator (Ngen.exe) ?
Ngen.exe creates compiled processor-specific machine code called native images which are files and installs them into the native image cache on the local computer. The runtime will use native images from the cache rather than using the JIT compiler to compile the original assembly.
32) What is Code Document Object Model (CodeDom) ?
Code Document Object Model are code generators which are used to minimize repetitive coding tasks, and to minimize the number of human-generated source code lines.
33) What is the difference between custom controls and user controls?
Custom controls are basically compiled code i.e. DLLs. These can be easily added to toolbox, so it can be easily used across multiple projects using drag and drop approach. These controls are comparatively hard to create.
But User Controls (.ascx) are just like pages (.aspx). These are comparatively easy to create but tightly couple with respect to User Interface and code. In order to use across multiple projects, we need to copy and paste to the other project as well.
34) What are the different types of Validation controls in ASP.NET?
In order to validate user input, ASP.NET provides validation server controls. All validation controls inherits from BaseValidator class which contains the common validation properties and methods like ControlToValidate,Enabled, IsValid, EnableClientScript, ValidationGroup,Validate() etc.
ASP.NET provides a range of validation controls:
• RequiredFieldValidator validates compulsory/required input.
• RangeValidator validates the range. Validates that input falls between the given range values.
• CompareValidator validates or compares the input of a control with another control value or with a fixed value.
• RegularExpressionValidator validates input value against a defined regular expression pattern.
• CustomValidator allows to customize the validation logic with respect to our application logic.
• ValidationSummary displays all errors on page collectively.
35) What are the types of Authentication in ASP.NET?
There are three types of authentication available in ASP.NET:
• Windows Authentication: This authentication method uses built-in windows security features to authenticate user.
• Forms Authentication: authenticate against a customized list of users or users in a database.
• Passport Authentication: validates against Microsoft Passport service which is basically a centralized authentication service.
36) What are the benefits of .NET Framework?
.NET Framework offers many benefits to application developers. Some of these benefits are as follows:
Consistent programming model —.NET Framework provides a consistent object-oriented programming model across various languages. You on we this model to create programs for performing different tasks, such as connecting to and retrieving data from databases and reading from and writing to files.
Language interoperability —Language interoperability is a feature that enables a piece of code written in one language to be used in another language. This facilities the reuse of code and therefore improves the efficiency of the development process.
Automatic management of resources —Wink developing .NET. applications, you may use various resources, such as files, memory, and database connecters. With MET Framework, you do not need to manually free these resources when they are no longer required.
Ease of deployment- .NET framework makes the deployment of applications easier. To install an application that is not based on NET Framework you need to copy It and its components on target computers. However, with MET Framework, you can quickly Install or deploy the applications such that Installation of new applications or components does not affect the existing applications.
37) Mention the core components of .NET Framework.
The two core components of .NET Framework are:
Common Language Runtime
.NET Framework Class Library.[sociallocker]
38) Briefly describe MSIL.
.NET Framework is shipped with compilers of all Programming languages to develop Programs. There are separate compilers for the Visual Basic, CS, and Visual C++ programming Languages in .NET Framework Each .NET compiler produces an intermediate aide after Compiling the source code. The Intermediate code is common for all languages and Is understandable only to NET environment. This intermediate code IS known as MSIL. MSIL file Is an executable file that can be transferred across various machines.
39) Briefly describe the roles of CLR in .NET Framework.
CLR provides an environment to execute MET applications on target machines.
CLR-is also a common runtime environment for all MET code irrespective of their programming language, because the compilers of MET Framework convert every source code into a common language known as MSIL .
CLR also provides various services to execute processes, such as memory management service and security services..CLR performs various tasks to manage the execution process of MET applications. The responsibilities of as are listed below:
Automatic memory management–CLR invokes venous built-in functions of MET Framework to allocate and de-allocate the memory of MET objects. Therefore, programmers need not write the code to explicitly allocate and de-allocate memory to programs.
Garbage Collection —Garbage collection Is the major role of CUR, with prevents memory leaks during execution of programs. The Garbage collector of CLR automatically determines the best time to free the memory, which is reserved by an object for execution.
Code Access Security —Code Access Security (CAS) model is used in MET Framework to impose restrictions and security during execution of programs. CLR uses security objects to manage access to code during execution of MET applications. as allows an executing code to perform only those tasks for which it has permission.
40) What is the role of the /IT complier In .NET Framework?
The MT complier is an important element of as, with loads 14.511 on target machine for execution. The MSIL is stored in MET assemblies after the developer has compiled the code written in any .NET. compliant programming language, such as Visual Basic and C#.
41) What is CTS?
CTS is the component of CUL through which WET Framework provides support for multiple languages because it contains a type system that is common across ate languages. Two CIS-compliant languages do not require type conversion when calling the cede written in one language from within the code written in another language. CTS provides a base set of data types for al the languages supported by.NET Framework. This means that the size of integer and long variables is the Same across ah .NET compliant programming languages. However, each language uses aliases for the base data types provided by CTS. For example, CTS uses the data type system. Int32 to represent a 4 byte integer value; however, Visual Basic uses the alias Integer for the same, whereas Cl uses the alias int. This is done for the sake of clarity and simplicity.
42) What Is CLS?
Common Language Specification (CLS) is a set of basic rules, which enables interoperability between two .NET-complaint languages. CIS is a subset of CTS; therefore, the languages supported by CLS can use each other’s c lass libraries similar to their own. Application programming interfaces (APIS), which we designed by following the rules defined In CLS, can be used by W .NET-compliant languages.
43) What Is managed code?
Managed code is the code that Is executed directly by the CLR. The applications created by using managed code automatically have CLR services such as type Checking, security, and automatic garbage collection. These services Help provide platform and language independence for managed code applications. The CLR compiles the source code to MSIL, not machine code. This MSIL along with the metadata that describes the attributes, classes and methods of the code resides an assembly.
44) What is an assembly?
An assembly is the primary building block of .NET Framework applications. In .NET, every application is compiled into an assembly, which refers to a portable executable (PE) file. The PE file can be either a dynamic Link library of an executable (.exe file).that contains the MSIL code of the compiled application. In addition to the MS11, an assembly also contains the files and resources necessary for the application, assembly metadata, and’ type metadata. An assembly stores the information about itself such as the name, version number of the assembly, and security information, which Is called metadata. Ibis also o ceded the assembly metadata. The type metadata is the information about the types (classes, structures, interfaces, and enumerations) required for the assembly.
45) Explain the different types of assemblies.
Assemblies are of two types, private and shared assemblies. A private assembly is used by the clients of the same application directory structure as the assembly. A shared assembly is stored in the global assembly cache (GAC), which is a repository of assemblies maintained by the runtime. A Shared assembly can be referenced by more than one application.
46) Can one DLL file contains the compiled code of more than one .NET language?
No, a DLL file can contain the complied code of only one programming language.
47) What Is the maximum number of classes that can be contained In one DLL file?
There is no limit to the number of classes that can be curtained In a DLL file.
48) Explain the differences between managed and unmanaged code?
Managed code is the code that is executed chatty by the QR Instead of the operating system. Unmanaged code is the code that is executed directly by the operating system outside the OR environment. In managed code, since the execution of the code Is governed by CLR, the runtime provides different services such as garbage collection, type checking, exception handling, and safety and support These sat help provide uniformly in platform and language-Independent behavior of managed code applications. In unmanaged code, the allocation of memory, type safety, and security is required to be taken are of by the developer. If the unmanaged code is not Properly handles, may result In memory leak. Examples of unmanaged code are ActiveX components and Wm32 AM that execute beyond the scope of native CLR.
49) Mention the execution process for managed code.
A piece of managed code is executed as follows:
1. Chasing a language compiler
2. Compiling the code to MSIL
3. Compiling MSIL to native code
I. Creating the code
50) Difference between int and int32?
Both are the same. system. int32 is a .NET class and int is an alias name for System. Int32.
51) What is side-by-side execution? Can two applications, one using a private assembly and other using a shared assembly, be stated as side-by-side executables?
Side-by-side execution Is the ability to run multiple versions of an application or component on the same computer. You can have multiple versions of the CLR and multiple versions of applications and components Mat use a version of the runtime on the same computer at the same time. As versioning is only applied to shared assemblies and not to private assemblies, two applications, one using a private assembly and other using a shared assembly, cannot be stated as side-by-side executables.
52) Why Is string called Immutable data type?
A sting represents text and stores a sequential collection of characters in the memory. A string object is said to be immutable (read only), because a value once assigned to a string object cannot be changed after the acting object has been created. When the value In the string object is modified, a new string object is created with a new value assigned to the string object therefore, keeping the old string In memory for garbage collector to be disposed.
53) What is code access security?
Code access security (CAS) is part of the .NET security mode that determines whether or not a piece of code is allowed to run and what resources it can use while running.
54) What are the advantages of ASP.NET MVC?
1. Extensive support for TDD. With asp.net MVC, views can also be very easily unit tested.
2. Complex applications can be easily managed
3. Separation of concerns. Different aspects of the application can be divided into Model, View and Controller.
4. ASP.NET MVC views are light weight, as they donot use viewstate. [/sociallocker]