简体   繁体   中英

Why can't a struct inherit from a class, but all structs inherit from the class "object"?

public class C {}
public struct S : C {}
public class Test
{
    public static void Main() {}
}

This doesn't compile. Every struct implicitly inherits from the class ValueType , which inherits from the class object . How is this possible?

A Structure is a type of value, not a class. Structures cannot inherit from another class or structure. You should consider reading the documentation about structures here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM