.NET Framework Interview Questions and Answers (547) - Page 6

What is the common language runtime (CLR)?

The common language runtime (CLR) is major component in the .NET Framework and it is the execution engine for .NET Framework applications.

It is responsible for proving the number of services, including the following:

1. Code management (loading and execution)

2. Verification of type safety

3. Conversion of Microsoft Intermediate Language (MSIL) to native code

4. Access to metadata (enhanced type information)

5. Managing memory for managed objects

6. Enforcement of code access security (See what is code access security?)

7. Exception handling, including cross-language exceptions

8. Interoperation between managed code, COM objects, and pre-existing DLLs (unmanaged code and data)

9. Automation of object layout

10. Support for developer services (profiling, debugging, and so on)
What is the common type system (CTS)?

The common type system (CTS) is a rich type system, built into the common language runtime (CLR) that supports the types and operations found in most of .NET programming languages. The common type system supports the complete implementation of a wide range of programming languages.
What is the Microsoft Intermediate Language (MSIL)?

MSIL is the Machine independent Code into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing, and calling methods on objects. Combined with metadata and the common type system, MSIL allows for true cross language integration. Prior to execution, MSIL is converted to machine code via CLR’s Just-in-Time (JIT) compiler.
What is managed code and managed data?

We can describe this Manage code like, if a code running under the control CLR, then we can call it as Managed Code.

Managed code is code that is written to target the services of the common language runtime (see what is CLR?). In order to target these services, the code must provide a minimum level of information (metadata) to the runtime. All C# (when not using the unsafe keyword), Visual Basic .NET, J#, and JScript .NET code is managed by default. Visual Studio .NET C++ code is not managed by default, but the compiler can produce managed code by specifying a Command-line switch (/CLR). Closely related to managed code is managed data—data that is allocated and reallocated by the common language runtime's garbage collector. C#, Visual Basic.NET, J# and JScript .NET data is managed by default. C# data can, however, be marked as unmanaged through the use of special keywords. Visual Studio .NET C++ data is unmanaged by default (even when using the /CLR switch), but when using Managed Extensions for C++, a class can be marked as managed by using the __gc keyword. As the name suggests, this means that the memory for instances of the class is managed by the garbage collector. In addition, the class becomes a full participating member of the .NET Framework community, with all of the benefits and restrictions that brings. An example of a benefit is proper interoperability with classes written in other languages (for example, a managed C++ class can inherit from a Visual Basic.NET class). An example of a restriction is that a managed class can only inherit from one base class. Any restrictions, such as this one, are designed to prevent common programming errors.
What is strong name?

A name that consists of an assembly's identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly.
What is portable executable (PE)?

The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR. The specification for the PE/COFF file formats is available at
http://www.microsoft.com/whdc/hwdev/hardware/pecoffdown.mspx
What is Code Access Security (CAS)?

CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running. For example, it is CAS that will prevent a .NET web applet from formatting your hard disk.
What is serialization in .NET?

Serialization is the process of converting an object into a stream of bytes.
What is Deserialization in .NET?

Deserialization is the opposite process of serialization, creating an object from a stream of bytes.
What is exception handling?

When an exception occurs, the system searches for the nearest catch clause that can handle the exception, as determined by the run-time type of the exception. First, the current method is searched for a lexically enclosing try statement, and the associated catch clauses of the try statement are considered in order. If that fails, the method that called the current method is searched for a lexically enclosing try statement that encloses the point of the call to the current method. This search continues until a catch clause is found that can handle the current exception, by naming an exception class that is of the same class, or a base class, of the run-time type of the exception being thrown. A catch clause that doesn't name an exception class can handle any exception.
Once a matching catch clause is found, the system prepares to transfer control to the first statement of the catch clause. Before execution of the catch clause begins, the system first executes, in order, any finally clauses that were associated with try statements more nested that than the one that caught the exception.
Exceptions that occur during destructor execution are worth special mention. If an exception occurs during destructor execution, and that exception is not caught, then the execution of that destructor is terminated and the destructor of the base class (if any) is called. If there is no base class (as in the case of the object type) or if there is no base class destructor, then the exception is discarded.
What are the contents of assembly?

In general, a static assembly can consist of four elements:

• The assembly manifest, which contains assembly metadata.
• Type metadata.
• Microsoft intermediate language (MSIL) code that implements the types.
• A set of resources.
What are the different types of assemblies?

Private, Public/Shared, Satellite
What is the difference between a private assembly and a shared assembly?

1. Location and visibility: A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. the .NET framework classes.

2. Versioning: The runtime enforces versioning constraints only on shared assemblies, not on private assemblies
What is the difference between ref & out parameters?

An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.
What is the difference between Array and Arraylist?

As elements are added to an ArrayList, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.
What is Jagged Arrays?

A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array-of-arrays."
What are indexers?

Indexers are similar to properties, except that the get and set accessors of indexers take parameters, while property accessors do not.
What is Interop Services?

The common language runtime(CLR) provides two mechanisms for interoperating with unmanaged code:

• Platform invoke, which enables managed code to call functions exported from an unmanaged library.

• COM interop, which enables managed code to interact with COM objects through interfaces.

Both platform invoke and COM interop use interop marshaling to accurately move method arguments between caller and callee and back, if required.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories