Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Override and Access Modifier Keyword Preferred Order

Tags:

c#

keyword

Which ordering is preferred for the override keyword and the access modifer (public, private, etc.) for methods? Both of the following seem to compile and do the same thing:

    public override string ToString ()
    {
        return "access modifier first";
    }

 

    override public string ToString ()
    {
        return "override keyword first";
    }

In Java, the order of keywords is typically enforced, so this flexibility seems startling. Apparently this flexibility is in Java, too (static public void main (String [] args) works...).

like image 452
101100 Avatar asked Sep 19 '25 14:09

101100


1 Answers

ReSharper, a plug-in for VS which provides several coding assistants like extended auto-completion, places the access modifier first. This would indicate that even if the C# spec is more flexible, most people expect to see it this way.

It's odd though because to use ReSharper's auto-complete for a method, you would type in "override" and then IntelliSense gives a list of overridable methods. Then, when you pick one, it restructures the definition so the access modifier is first.

like image 117
KeithS Avatar answered Sep 21 '25 04:09

KeithS