Why are private virtual methods illegal in C#?

后端 未结 6 553
轮回少年
轮回少年 2020-12-02 13:05

Coming from a C++ background, this came as a surprise to me. In C++ it\'s good practice to make virtual functions private. From http://www.gotw.ca/publications/mill18.htm: \

6条回答
  •  庸人自扰
    2020-12-02 13:51

    In C# (and in the CLI, as far as i've seen), "private" has a pretty clear and unambiguous meaning: "accessible only in this class". The concept of private virtuals screws that all up, not to mention making namespaces a bit of a minefield. Why should i have to care what you've called a method i can't even see, and get a compiler warning for happening to have chosen a name you already snagged for it?

提交回复
热议问题