MyClass equivalent in C#

前端 未结 3 1242
醉梦人生
醉梦人生 2021-02-18 22:33

In looking at this question, commenter @Jon Egerton mentioned that MyClass was a keyword in VB.Net. Having never used it, I went and found the document

3条回答
  •  执念已碎
    2021-02-18 23:23

    According to Jon Skeet, there is no such equivalent:

    No, C# doesn't have an equivalent of VB.NET's MyClass keyword. If you want to guarantee not to call an overridden version of a method, you need to make it non-virtual in the first place.

    An obvious workaround would be this:

    public virtual void MyMethod()
    {
        MyLocalMethod();
    }
    
    private void MyLocalMethod()
    {
        ...
    }
    

    Then you could call MyLocalMethod() when a VB user would write MyClass.MyMethod().

提交回复
热议问题