Compiler Error CS1721

 

Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Class 'class' cannot have multiple base classes: 'class_1' and 'class_2'

The most common cause of this error message is attempting to use multiple inheritance. A class in C# may only inherit directly from one class. However, a class can implement any number of interfaces.

The following example shows one way in which SC1721 is generated, and then shows two possible ways to avoid the error.

// CS1721.cs  
public class A {}  
public class B {}  
public class MyClass : A, B {}   // CS1721  
  
// One possible fix is to use the following approach instead:  
public class A {}  
public class B : A {}  
public class C : B {}  
  
// Another possible fix is to use interfaces instead of base classes:  
public class A {}  
public interface B {}  
public class C : A, B {}  
  

Polymorphism
Interfaces

Show: