简体   繁体   中英

Why does the Type attribute of a static class show "abstract" in C#?

Main Code:

public class ReflectionsDemo
{
    public void demo()
    {
        Type t = typeof(StaticClassDemo);
        Console.WriteLine(t.Attributes);
    
    }
}

StaticClassDemo is just a static class with a couple of static methods.

Output: AutoLayout, AnsiClass, Class, Public, Abstract, Sealed

I don't understand that a static class won't be an abstract class, but why it is having abstract as an attribute?

"Abstract" sort of means "you cannot create an instance of this type"

"Sealed" means "you cannot inherit from this type"

Together, if you squint a little, they describe a static class.

The " static class " feature was not available from the start, so I assume that rather than introduce a new attribute to describe it, the creators used the combination of these existing attributes.

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