Home > Backend Development > C++ > Why Can't I Inherit Enums in C#?

Why Can't I Inherit Enums in C#?

Patricia Arquette
Release: 2025-01-26 07:26:09
Original
126 people have browsed it

The reason why enumeration cannot be inherited in the c#

Why Can't I Inherit Enums in C#?

C# does not support enumeration inheritance

Although the "inheritance" enumeration in the middle layer naming space is very convenient, unfortunately, C# cannot be achieved. Meeting cannot inherit from others, but can only inherit from system.enum.

The grammar that looks like inherited is actually a way to change the underlying value of enumeration. However, all enumerations are still derived from System.enum. This act is specified in the CLI specification:

"All enumeration must be derived from System.enum"
  • "For the above reasons, all enumerations are valuable, so they are sealed"
  • As you mentioned, because you need to use an enumeration service defined by WSDL and XSD, the constant in the class cannot be used. In this case, enumeration cannot be modified.

The above is the detailed content of Why Can't I Inherit Enums in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template