About Me

All about Real time requirements in Orale Stay Tune!!

Sunday, April 6, 2008

C# INTERVIEW QUESTIONS

What namespaces are necessary to create a localized application?

System.Globalization and System.Resources.

What is the smallest unit of execution in .NET? an Assembly.When should you call the garbage collector in .NET?

As a good rule, you should not call the garbage collector. However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.


How do you convert a value-type to a reference-type?

Use Boxing.


What happens in memory when you Box and Unbox a value-type?

Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.


Difference between directcast and ctype.

Answer1DirectCast requires the run-time type of an object variable to bethe same as the specified type.The run-time performance ofDirectCast is better than that of CType, if the specified type and the run-time typeof the expression are the same. Ctype works fine if there is a valid conversion defined between the expression and the type.

Answer2The difference between the two keywords is that CType succeeds as long as there is a valid conversion defined between the expression and the type, whereas DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType.


An example of a ctype and directcast.

In the preceding example, the run-time type of Q is Double. CType succeeds because Double can be converted to Integer, but DirectCast fails because the run-time type of Q is not already Integer


ctype(123.34,integer) - should it throw an error? Why or why not?

Answer1It would work fine. As the runtime type of 123.34 would be double, and Double can be converted to Integer.

Answer2the ctype(123.34,integer) will work fine no errors


directcast(123.34,integer) - should it throw an error? Why or why not?

It would throw an InvalidCast exception as the runtime type of 123.34 (double) doesnt match with Integer.

0 comments: