CSharp Interview Questions: Part 4

  1. And if they have conflicting method names?
    It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
  2. 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.
  3. How can you overload a method?
    Different parameter data types, different number of parameters, different order of parameters.
  4. 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.
  5. 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.
  6. 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.