(Interview) Microsoft Technologies Interview Questions (.Net Framework)

Microsoft Technologies Interview Questions

[ .Net Framework Questions ]

 

What is CTS ?

CTS is an acronym for Common Type System which is an integral part of .net and which ensures language compatibility, interoperability and integration. Because .net treats all languages equal a class written in C# should be equivalent to class written in VB.net. Languages must agree on the meaning of these concepts before they can integrate with one another. To make this integration possible Microsoft has specified a common type system which every .net language must follow.

There are two types in CTS: value type and reference type. Value types reference values on the stack. When a value type is passed to a function they are passed by value i.e. original value of the passed variable will not change.

If a type consumes memory then it should be declared as a reference type. They contain references to heap based objects and are reclaimed by the garbage collector. When you pass a variable by reference then if the called function modifies it, it is visible in the calling function because it works on the actual object contrast to value type where a copy of the object is passed.

Explain the concept of CLR ?

The most important component of the .net framework is the CLR or the Common Language Runtime. The CLR manages and executes code written in .net languages. It activates objects, performs security checks, lays them out in memory, executes them and garbage collects these objects as well.

The CLR is a runtime engine that loads required classes, performs just in time compilations, enforces security checks and a bunch of other runtime functions.

The CLR executables are either exe or dll files that consist mostly of metadata and code. These executables must adher to a file format called the Portable Executable (PE) file format

Explain what is .net remoting ?

Like DCOM, RMI, CORBA which are remoting technologies, .Net Remoting is a new entry in this list of remoting technologies. It is a system for different applications to use to communicate with one another. The applications can be located on the same computer, different computers on the same network or even computers across a network.

Objects that can be accessed using remoting are remotable objects. These objects are accessed trough channels which transport the messages to and from remote objects. These channels are of two types depending upn the protocol used for communication: HttpChanel or TCPChannel.

To create a remotable object one needs to create a class inheriting from MarshalByRefObject.

using System;
using System.Runtime.Remoting;

namespace Remoting
{
///
/// Object to demonstrate the use of .NET Remoting.
///
public class RemotableObject : MarshalByRefObject
{
}
}

What is Reflection ? What is the support for Reflection in .Net ?

The metadata of any .net assembly can be inspected at runtime for its type, method, properties, and events and so on. The mechanism to do this is termed as reflection and there are classes in .net which enable you to do so.  One can determine all classes that an assembly contains, members exposed by these classes, parameters the members expect, etc. The classes that enable you to do so reside in the System.Reflection namespace. An object?s metadata is accessed through its Type class which is retrieved using the GetType() method.  Type T = MyClass.GetType (); One you have the type you can access it to get all other information of the class.

What are Web Services ? Give an example ?

Web services allow access to software through standard web protocols such as HTTP and SMTP. They enable software to interact with a wider range of clients. Web services can be consumed by any application that understands how to parse an XML. XML is the key technology used in web services.

Microsoft .net web services support three protocols HTTP GET, HTTP POST and SOAP (Simple Object Access Protocol).

For the clients to interact with the web services there must be a description of the method calls or interface that the web service supports. This web service description document is found in the XML schema called as WSDL (Web services description language).

What are HttpPost and HttpGet ?

Both HTTP GET and HTTP POST use HTTP (Hyper Text Transfer Protocol) as the underlying protocol. The GET and POST methods have been widely in Servlets, CGI, ASP, and many more. Both of these methods encode the request parameters as name value pairs in the HTTP request. The GET method creates a query string and appends it to the script?s URL on the server that handles the request. For the POST method the values are passed in the body of the HTTP request message.

What is garbage collection ?

Like a Java Virtual Machine, the CLR removes the burden of memory management from developers by destroying objects once they are no longer being referenced. Before an object is removed from memory, it must free any resources it has allocated during its lifetime. In C++, this ?cleanup code? is usually housed in an object?s destructor, whereas in VB it is placed in the Class Terminate () method. Under the .NET Framework, cleanup code must reside in an object?s Finalize () method, which is called just before the object is garbage-collected by the CLR. Finalize () is a method in the System.Object class from which all other .NET classes derive. You only have to override this method when you have cleanup code that should be performed before the class is destroyed.

For performance reasons, the Finalize () method should only be employed when efficiently freeing a particular resource is a prime concern.

What is IL (Intermediate Language) in .Net ?

In software engineering the concept of abstraction is extremely important. Microsoft calls its own language abstraction layer the Common Intermediate Language (CIL). Similar to byte code like Java generates IL supports all object oriented features including data abstraction, inheritance, polymorphism, etc. In addition to these features IL supports other concepts such as properties, fields and enumeration. Any .net language can be converted into IL, so .net supports multiple languages and perhaps multiple platforms. CIL is also called as MSIL (Microsoft Intermediate Language). When .net code is compiled it is converted into IL, which is then executed. Because of IL objects created in one language can be accessed and derived from another. E.g. it is possible to create a class in VB.Net and derive from it in C#.

What are the classes to support Multithreading in .Net ?

Threads are lightweight programs responsible for multitasking within a single application. The System.Threading namespace provides classes to manage multithreaded applications.

The simplest way to create a thread is to create a new instance of the Thread class. CLR provides ThreadStart delegate which points to a method which starts when the thread starts running.

Thread myThread = new Thread (new ThreadStart(myfunc));

There are API?s to join threads, suspend threads and killing threads as well.