Compiler Error CS1721
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.
Example
The following example shows one way in which CS1721 is generated:
// CS1721.cs
public class A {}
public class B {}
public class MyClass : A, B {} // CS1721
To correct this error
The following are different ways to correct this error:
Make class
B
inherit fromA
, andMyClass
inherit fromB
:public class A {} public class B : A {} public class MyClass : B {}
Declare
B
as an interface. MakeMyClass
inherit from the interfaceB
, and the classA
:public class A {} public interface B {} public class MyClass : A, B {}
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for