Thursday, April 2, 2009

C# Interview Questions Part III

21. What’s the difference between an interface and abstract class?

Ans. 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.

22. How can you overload a method?

Ans. Different parameter data types, different number of parameters, different order of parameters.

23. 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?

Ans. 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.

24. What’s the difference between System.String and System.StringBuilder classes?

Ans. System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

25. What’s the advantage of using System.Text.StringBuilder over System.String?

Ans. StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

26. Can you store multiple data types in System.Array?

Ans. No.

27. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

Ans. The first one performs a deep copy of the array, the second one is shallow.

28. How can you sort the elements of the array in descending order?

Ans. By calling Sort() and then Reverse() methods.

29. What’s the .NET datatype that allows the retrieval of data by a unique key?

Ans. HashTable.

30. What’s class SortedList underneath?

Ans. A sorted HashTable.

No comments: