What is the difference between public, static and void?

Public, static and void are three different modifiers that can be used in C#. each one serves a different purpose.

Public – The public modifier is the most liberal modifier in C#. It is a type of access modifiers, which can be accessed from anywhere inside or outside the class. Public modifiers are public, i.e. not private. They is no access restriction on a public modifier. The public keyword is used just before the class keyword to declare class as public.

Static – The static method is a method that is used to declare that the Main method is a global one. Hence, it can be used and called without a need to create an instance of that class. The static class can be addressed by the using the class name followed by the operator and method name. The compiler stores the static method’s address and uses it before any object is created for execution.

Void –Void is a type modifier. It states that that the Main method does not return any value.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.