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

前端 未结 10 1165
生来不讨喜
生来不讨喜 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:44

    I don't know if this qualifies as an answer, but I would point out that "static classes" are more of a language concept and less of a CLR concept. From the point of view of the CLR, they are just classes, like any other. It's up to the language to enforce all the rules you described.

    As such, one advantage of the current implementation is that it does not add further complexity to the CLR, which all CLR-targeting languages would have to understand and model.

提交回复
热议问题