How to achieve multiple inheritances in C#?

  • You cannot inherit from multiple classesin c# by default.
  • But you may use interfaces or a combination of one class and interface(s), where interface(s) should be followed by class name in the signature.


    interface A
    { }
    interface B
    { }
    Class BaseClass {}
    class DerivedClass : A, B { } // from multiple Interface(s) 
    class DerivedClass : Base, B { } // from one Class and Interfacce(s)‚Äč 

What is static class in c#

Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class

Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object.

The main features of a static class are:

What is a field in CSharp?

  • Properties expose fields.
  • Fields should (almost always) be kept private to a class and accessed via get and set properties.
  • Properties provide a level of abstraction allowing you to change the fields while not affecting the external way they are accessed by the things that use your class.


public class MyClass
    // this is a field.  It is private to your class and stores the actual data.
    private string _myField;

    // this is a property. When accessed it uses the underlying field,
    // but only exposes the contract, which will not be affected by the underlying field
    public string MyProperty
            return _myField;
            _myField = value;

    // This is an AutoProperty (C# 3.0 and higher) - which is a shorthand syntax
    // used to generate a private field for you
    public int AnotherProperty{get;set;} 

What is a generic class in csharp?

  • Generic classes encapsulate operations that are not specific to a particular data type.
  • The most common use for generic classes is with collections like linked lists, hash tables, stacks, queues, trees, and so on.
  • Operations such as adding and removing items from the collection are performed in basically the same way regardless of the type of data being stored.


class BaseNodeGeneric<T> { }