Home
C-Sharp
Interview FAQs

Show

FAQs of level

Yes. The params keyword can be applied to a method parameter which is an array. Upon method invocation, the array elements can be supplied as a comma (,) separated list.
Use the String.Compare function. Its third parameter is a boolean which specifies whether case should be ignored or not.

"fred" == "Fred" // false
System.String.Compare( "fred", "Fred", true ) == 0 // true

For more control over the comparison, e.g. exotic features like width-sensitivity, consider using System.Globalization.CompareInfo.Compare(), e.g.
CultureInfo.CurrentCulture.CompareInfo.Compare(
"fred", "Fred",
CompareOptions.IgnoreCase |
CompareOptions.IgnoreKanaType |
CompareOptions.IgnoreWidth
);
Yes. An IndexOutOfRange exception is used to signal an error.
No. C# constructors cannot be inherited.

If constructor inheritance were allowed, then necessary initialization in a base class constructor might easily be omitted. This could cause serious problems which would be difficult to track down. For example, if a new version of a base class appears with a new constructor, your class would get a new constructor automatically. This could be catastrophic.

In C++, objects are constructed from base class to derived class. This means that when the base class constructor is running the object is effectively a base object. So, C++ virtual method calls are directed to the base class implementation.

In .NET on the other hand, the derived constructor is executed first. This means the object will be a derived object; and, virtual method calls are directed to the derived implementation.

The C# compiler inserts a call to the base class constructor at the beginning of any derived constructor in order to maintain OO semantics, i.e. that the base class constructor is called first.

In a similar fashion, when C# destructors call virtual methods, virtual method calls from a base destructor are directed to the derived implementation.

Therefore, in C#, a virtual method can be called from a constructor or destructor. But, usually, it is a bad idea. .NET object construction is very different from C++ object construction; and, virtual method calling is affected.

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.
Yes. If you are debugging via Visual Studio.NET, just go to Immediate window.
To the Console or a text file depending on the parameter passed to the constructor.
By definition, a C# destructor is virtual. Because, a C# destructor is basically an override of the Finalize method of System.Object. Therefore, there is no need to make a C# destructor virtual.
PreviousDisplaying 8 of 25Next
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*