Saturday, March 6, 2010

C# and Dot Net Interview Questions

What is the use of fixed statement
The fixed statement sets a pointer to a managed variable and “pins” that variable during the execution of statement.
Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably. (In fact, the C# compiler will not allow you to set a pointer to a managed variable except in a fixed statement.)
Eg: Class A { public int i; }
A objA = new A; // A is a .net managed type
fixed(int *pt = &objA.i) // use fixed while using pointers with managed
// variables
{
*pt=45; // in this block use the pointer the way u want
}

What is the order of destructors called in a polymorphism hierarchy
Destructors are called in reverse order of constructors. First destructor of most derived class is called followed by its parent’s destructor and so on till the topmost class in the hierarchy.
You don’t have control over when the first destructor will be called, since it is determined by the garbage collector. Sometime after the object goes out of scope GC calls the destructor, then its parent’s destructor and so on.
When a program terminates definitely all object’s destructors are called.

How can you sort the elements of the array in descending order
int[] arr = new int[3];
arr[0] = 4;
arr[1] = 1;
arr[2] = 5;
Array.Sort(arr);
Array.Reverse(arr);

Is it possible to Override Private Virtual methods
No: First of all you cannot declare a method as ‘private virtual’.

What does the volatile modifier do
The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment.
The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread.

What is the C# equivalent of System.Single
Float 32 bit
e.g. float i = 6.8F; // or 6.8f
By default, a real numeric literal on the right-hand side of the assignment operator is treated as double. Therefore, to initialize a float variable use the suffix f or F.
If you don’t use the suffix in the previous declaration, you will get a compilation error because you are attempting to store a double value into a float variable.

A single line comments are implemented by
//

Code running under the control of CLR is often referred as
Managed Code

Platform specific code is obtained when
MSIL code is the intermediate code which is platform independent.
When MSIL is compiled actual platform dependent code is generated.

Intermediate Language also facilitates language interoperability
True

NET interfaces are not derived from IUnknown & they do not have associated GUID’s
True

Code written in C# can not used in which of the languages
Java

It is not possible to debug the classes written in other .Net languages in a C# project.
False: It is definitely possible to debug other .Net languages code in a C# project. As everyone knows .net can come

No comments:

Post a Comment