What if I write static public void instead of public static void in c sharp?

Viewed 74

Since I'm new to OOPS concept,What if I write static public void instead of public static void in c sharp? Will that make any difference?

3 Answers

The C# language specification defines a method header in chapter 15.6.1 as

method-header: attributesopt method-modifiersopt partialopt return-type member-name type-parameter-listopt ( formal-parameter-listopt ) type-parameter-constraints-clausesopt

and

method-modifiers:
method-modifier
method-modifiers method-modifier

So the order is

  • Attributes ([Something]) must go first
  • Modifers come next (new public protected internal private static virtual sealed override abstract extern) in any order (that's what you're asking about)
  • partial must be before the return type
  • the return type is before the method
  • the return type generics (<Something>) comes before parameters
  • parameters in parentheses
  • and a where clause last
  • It won’t make any difference as long as your method name comes last and the return type of your method comes second last.

  • It's generally a best practice to put the access specifier (i.e public, private, protected) at the start

No, this is pure standard coding guidelines, the generated code will be exactly the same. The general guideline is to put the visibility keyword first.

I suggest you to use the StyleCop analyzer in order to be used to efficient, standard guidelines : https://github.com/DotNetAnalyzers/StyleCopAnalyzers

Related