Thursday, February 10, 2011

C# Interview Questions

Part III

1) What’s the difference between an interface and abstract class?
 In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.

2) How can you overload a method?
Different parameter data types, different number of parameters, different order of parameters.

3) If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
4) What’s the difference between System.String and System.StringBuilder classes?
System.String is immutable, System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

5) Is it namespace class or class namespace?
The .NET class library is organized into namespaces. Each namespace contains a functionally related group of classes so natural namespace comes first.

6) Does C# support multiple-inheritance?           No. But you can use Interfaces.

7) Where is a protected class-level variable available?          It is available to any sub-class derived from base class

8) Are private class-level variables inherited?         Yes, but they are not accessible.

9) Describe the accessibility modifier “protected internal”.          It is available to classes that are within the same assembly and derived from the specified base class.

10) Which class is at the top of .NET class hierarchy?            System.Object.

11).What does the term immutable mean?             The data value may not be changed.
            Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

12) What’s the difference between System.String and System.Text.StringBuilder classes?             System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

13) What’s the advantage of using System.Text.StringBuilder over System.String?            StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.

14) Can you store multiple data types in System.Array?              No.

15) What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?             The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.

16) How can you sort the elements of the array in descending order?           By calling Sort() and then Reverse() methods.

17) What’s the .NET collection class that allows an element to be accessed using a unique key?         HashTable.

18) What class is underneath the SortedList class?         A sorted HashTable.

19) Will the finally block get executed if an exception has not occurred?         Yes.

20) What’s the C# syntax to catch any possible exception?         A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

21) Can multiple catch blocks be executed for a single try statement?         No. Once the proper catch block processed, control is transferred to the finally block .

22) Explain the three services model commonly know as a three-tier application?           Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).

No comments:

Post a Comment