Why are static classes considered “classes” and “reference types”?

前端 未结 10 1159
生来不讨喜
生来不讨喜 2021-02-01 04:54

I’ve been pondering about the C# and CIL type system today and I’ve started to wonder why static classes are considered classes. There are many ways in which they are not really

10条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 05:29

    It's a class as far as the CLR is concerned. It's just syntactic sugar in the C# compiler, basically.

    I don't think there would be any benefit in adding a different name here - they behave mostly like classes which just have static methods and can't be constructed, which is usually the kind of class which became a static class when we moved from C# 1 to C# 2.

    Bear in mind that if you want to create a new name for it, that probably means a new keyword too...

提交回复
热议问题