DotNet Interview Questions

  • 1
     What is .NET Framework?

    .NET Framework is a complete environment that allows developers to develop, run, and deploy the following applications:

    • Console applications
    • Windows Forms applications
    • Windows Presentation Foundation (WPF) applications
    • Web applications (ASP.NET applications)
    • Web services
    • Windows services
    • Service-oriented applications using Windows Communication Foundation
    • Workflow-enabled applications using Windows Workflow Foundation (WF) 

    NET Framework also enables a developer to create sharable components to be used in distributed computing architecture. NET Framework supports the object-oriented programming model for multiple languages, such as Visual Basic, Visual C#, and Visual C++. .NET Framework supports multiple programming languages in a manner that allows language interoperability. This implies that each language can use the code written in some other language.

  • 2
    What are the main components of .NET Framework?

    .NET Framework provides enormous advantages to software developers in comparison to the advantages provided by other platforms. Microsoft has united various modern as well as existing technologies of software development in .NET Framework. These technologies are used by developers to develop highly efficient

    applications for modern as well as future business needs. The following are the key components of .NET Framework: 

    • NET Framework Class Library
    • Common Language Runtime
    • Dynamic Language Runtimes (DLR)
    • Application Domains
    • Runtime Host
    • Common Type System
    • Metadata and Self-Describing Components
    • Cross-Language Interoperability
    • .NET Framework Security
    • Profiling
    • Side-by-Side Execution 
  • 3
    List the new features added in .NET Framework 4.0.

    Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler. 

  • 4
    What is Manifest?

    Assembly metadata is stored in Manifest. Manifest contains all the metadata needed to do the following things

    • Version of assembly.
    • Security identity.
    • Scope of the assembly.
    • Resolve references to resources and classes. 

    The assembly manifest can be stored in a PE file either (an .exe or) .dll with Microsoft intermediate language (MSIL code with Microsoft intermediate language (MSIL) code or in a stand-alone PE file, that contains only assembly manifest information.

  • 5
    What are code contracts?

    Code contracts help you to express the code assumptions and statements stating the behavior of your code in a language-neutral way. The contracts are included in the form of pre-conditions, post-conditions and object-

    invariants. The contracts help you to improve-testing by enabling run-time checking, static contract verification, and documentation generation. 

  • 6
    Name the classes that are introduced in the System.Numerics namespace. 

    The following two new classes are introduced in the System.Numerics namespace: 

    • BigInteger - Refers to a non-primitive integral type, which is used to hold a value of any size. It has no lower and upper limit, making it possible for you to perform arithmetic calculations with very large numbers, even with the numbers which cannot hold by double or long.
    • Complex - Represents complex numbers and enables different arithmetic operations with complex numbers. A number represented in the form a + bi, where a is the real part, and b is the imaginary part, is a complex number. 
  • 7
    What is managed extensibility framework?

    Managed extensibility framework (MEF) is a new library that is introduced as a part of .NET 4.0 and Silverlight 4. It helps in extending your application by providing greater reuse of applications and components. MEF provides a way for host application to consume external extensions without any configuration requirement. 

  • 8
    What is the difference between int and int32.

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

  • 9
     Describe the roles of CLR in .NET Framework.

    CLR provides an environment to execute .NET applications on target machines. CLR is also a common runtime environment for all .NET code irrespective of their programming language, as the compilers of respective language in .NET Framework convert every source code into a common language known as MSIL or IL (Intermediate Language).

    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 .NET applications.

    The responsibilities of CLR are listed as follows:

    • Automatic memory management
    • Garbage Collection
    • Code Access Security
    • Code verification
    • JIT compilation of .NET code 
  • 10
    What is difference between System.String and System.StringBuilder classes?

    String and StringBuilder classes are used to store string values but the difference in them is that String is immutable (read only) by nature, because a value once assigned to a String object cannot be changed after its creation. When the value in the String object is modified, a new object is created, in memory, with a new value assigned to the String object. On the other hand, the StringBuilder class is mutable, as it occupies the same space even if you change the value. The StringBuilder class is more efficient where you have to perform a large amount of string manipulation.

  • 11
    What is the role of the JIT compiler in .NET Framework?

    The JIT compiler is an important element of CLR, which loads MSIL on target machines for execution. The MSIL is stored in .NET assemblies after the developer has compiled the code written in any .NET-compliant programming language, such as Visual Basic and C#.

    JIT compiler translates the MSIL code of an assembly and uses the CPU architecture of the target machine to execute a .NET application. It also stores the resulting native code so that it is accessible for subsequent calls. If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code. JIT compiler also enforces type-safety in runtime environment of .NET Framework. It checks for the values that are passed to parameters of any method.

    For example, the JIT compiler detects any event, if a user tries to assign a 32-bit value to a parameter that can only accept 8-bit value. 

  • 12
    What is Common Language Specification (CLS)?

    CLS is a set of basic rules, which must be followed by each .NET language to be a .NET- compliant language. It enables interoperability between two .NET-compliant languages. CLS is a subset of CTS; therefore, the languages supported by CLS can use each other's class libraries similar to their own. Application programming interfaces (APIs), which are designed by following the rules defined in CLS can be used by all .NET-compliant languages.

  • 13
    What is lazy initialization?

    Lazy initialization is a process by which an object is not initialized until it is first called in your code. The .NET 4.0 introduces a new wrapper class, System.Lazy, for executing the lazy initialization in your application. Lazy initialization helps you to reduce the wastage of resources and memory requirements to improve performance. It also supports thread-safety. 

  • 14
    What is Microsoft Intermediate Language (MSIL)?

    The .NET Framework is shipped with compilers of all .NET programming languages to develop programs. There are separate compilers for the Visual Basic, C#, and Visual C++ programming languages in .NET Framework. Each .NET compiler produces an intermediate code 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. 

  • 15
     Which is the root namespace for fundamental types in .NET Framework?

    System.Object is the root namespace for fundamental types in .NET Framework.

  • 16
    How can you instantiate a tuple?

    The following are two ways to instantiate a tuple: 

    • Using the new operator. For example, 
    Tuple t = new Tuple ("Hellow", 2);
    
    • Using the Create factory method available in the Tuple class. For example, 
    Tuple<int, int, int> t = Tuple.Create<int, int,int> (2, 4, 5);
    
  • 17
    Is there a way to suppress the finalize process inside the garbage collector forcibly in .NET?

    Use the GC.SuppressFinalize() method to suppress the finalize process inside the garbage collector forcibly in .NET.

  • 18
    Mention the execution process for managed code. 

    A piece of managed code is executed as follows:

    • Choosing a language compiler
    • Compiling the code to MSIL
    • Compiling MSIL to native code
    • Executing the code. 
  • 19
    What is Difference between NameSpace and Assembly?

    Following are the differences between namespace and assembly: 

    • Assembly is physical grouping of logical units, Namespace, logically groups classes.
    • Namespace can span multiple assembly. 
  • 20
    How does CAS works? 

    There are two key concepts of CAS security policy- code groups and permissions. A code group contains assemblies in it in a manner that each .NET assembly is related to a particular code group and some permissions are granted to each code group. For example, using the default security policy, a control downloaded from a Web site belongs to the Zone, Internet code group, which adheres to the permissions defined by the named permission set. (Normally, the named permission set represents a very restrictive range of permissions.) 

    Assembly execution involves the following steps:

    • Evidences are gathered about assembly.
    • Depending on the gathered evidences, the assembly is assigned to a code group.
    • Security rights are allocated to the assembly, depending on the code group.
    • Assembly runs as per the rights assigned to it. 
  • 21
    How can you turn-on and turn-off CAS?

    YOU can use the Code Access Security Tool (Caspol.exe) to turn security on and off.

    To turn off security, type the following command at the command prompt: caspol -security off

    To turn on security, type the following command at the command prompt: caspol -security on

    In the .NET Framework 4.0, for using Caspol.exe, you first need to set the element to true.

  • 22
    What are tuples?

    Tuple is a fixed-size collection that can have elements of either same or different data types. Similar to arrays, a user must have to specify the size of a tuple at the time of declaration. Tuples are allowed to hold up from 1 to 8 elements and if there are more than 8 elements, then the 8th element can be defined as another tuple. Tuples can be specified as parameter or return type of a method. 

  • 23
    What is code access security (CAS)?

    Code access security (CAS) is part of the .NET security model that prevents unauthorized access of resources and operations, and restricts the code to perform particular tasks. 

  • 24
    Which method do you use to enforce garbage collection in .NET?

    The System.GC.Collect() method.

  • 25
     Give a brief introduction on side-by-side execution. Can two applications, one using private assembly and the other using the shared assembly be stated as side-by-side executables? 

    Side-by-side execution enables you to run multiple versions of an application or component and CLR on the same computer at the same time. As versioning is applicable only 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. 

  • 26
    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 a .NET environment. So after compilation, the language is not a barrier and the code can call or use the function of another language also.

  • 27
    What is the use of Error Provider Control in .NET?

    The ErrorProvider control is used to indicate invalid data on a data entry form. Using this control, you can attach error messages that display next to the control when the data is invalid, as seen in the following image. A red circle with an exclamation point blinks, and when the user mouses over the icon, the error message is displayed as a tooltip.

  • 28
    What is the global assembly cache (GAC)?

    GAC is a machine-wide cache of assemblies that allows .NET applications to share libraries. GAC solves some of the problems associated with DLL’s (DLL Hell).

  • 29
    What is Click Once?

    ClickOnce is a new deployment technology that allows you to create and publish self-updating applications that can be installed and run with minimal user interaction.

  • 30
    What is the full form of ADO?

    The full form of ADO is ActiveX Data Object.

  • 31
    How can you identify that the page is posted back?

    There is a property, named as “IsPostBack” property. You can check it to know that the page is post backed or not.

  • 32
    What are the different types of indexes in .Net?

    There are two types of indexes in .Net:

    Clustered index and non-clustered index

  • 33
    Which method do you use to enforce garbage collection in .NET?

    The System.GC.Collect() method.

  • 34
    What is Common Type System (CTS)?

    CTS is the component of CLR through which .NET Framework provides support for multiple languages because it contains a type system that is common across all the languages. Two CTS-compliant languages do not require type conversion when calling the code written in one language from within the code written in another language. CTS provide a base set of data types for all the languages supported by.NET Framework. This means that the size of integer and long variables is same across all .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, C# uses the alias int. This is done for the sake of clarity and simplicity. 

  • 35
    What is an IL?

    Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code is compiled to IL. IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.

  • 36
    what is BCL?

    • The base class library is a set of .NET classes that provide common functionality such as data types, algorithms, cryptography, networking, string manipulation, file system access, database connectivity, exception handling, and more.
    • The binary Compatibility Layer is a layer between the CLR and managed applications. This layer ensures binary compatibility of the managed application with the existing versions of the CLR.
  • 37
    What is meant by reference type?

    A reference type contains the pointer to the address of the data, and the memory is stored in a heap by this type.

  • 38
    What do you understand by value type?

    Value type is something in .NET that stores the data directly in the stack memory.

  • 39
    What is custom control?

    Custom control is a dynamic layout that defines a single control. It has complete toolbox support and is derived from control.

  • 40

    Are there any validators in ASP.NET?

    Yes, there are two types of validators in ASP.NET. They are as follows:

    • Client side validation
    • Server side validation
  • 41
    What is Server.Transfer?

    Server.Transfer, unlike Response.Redirect, only transfers the user from one page to another. There is no trip back to the browser of the client.

  • 42
    What is Response.Redirect?

    Response.Redirect mainly performs a trip back to the browser of the client and redirects them to the new browser when the user changes or redirects to another page or site. The history of the user is also updated.

  • 43
    Explain the key difference between a class and an object.

    A class is a template of an object that is used to describe all methods and the properties of an application but it cannot become an object without instantiation.

  • 44
    What do you mean by globalization?

    When the applications are designed so that users and developers can use them from all around the world in various languages, it is called the globalization of the application.

  • 45
    What is localization?

    Localization is a process by which the applications used globally are changed and customized to be easy to access in a specific language or by a particular culture. In addition, they are altered to meet the criteria of a particular culture and locale.

  • 46
    What is SDI?

    SDI is called Single Document Interface. Unlike MDI, it only opens a single document in one window. There is no parent window and each window has its own components.

  • 47
     Explain public assembly.

    Public assembly is also known as a shared assembly. This type of assembly is not application-specific and can be accessed and shared by multiple applications. Unlike private assembly, it is only required to store the shared assembly at the system level, and there is no need to copy it to every folder that we need to work on with this assembly. It can be shared with multiple applications. Shared or private assembly is stored and installed in the GAC, which stands for Global Assembly Cache.

  • 48
    What are unmanaged codes?

    These are all the codes that are not managed by the common language runtime or the CLR. It is independent of the .NET framework. Since the common language runtime does not handle it, the execution and management of memory are done independently.

  • 49
    What are managed codes?

    These are the codes that CLR or Common Language Run-Time manages. It is useful in managing memory with the help of garbage collection. The execution of managed codes is done using .Net framework and is necessary for its implementation.

  • 50
    What is executescalar?

    ExecuteScalar is used in .NET to obtain only a single value that is the output value.