Home  >  Article  >  Backend Development  >  What is the difference between public, static and void keywords in C#?

What is the difference between public, static and void keywords in C#?

王林
王林forward
2023-09-06 23:01:021671browse

C# 中的 public、static 和 void 关键字有什么区别?

All these keywords are part of the main method of any C# program.

The Main method is the entry point for all C# programs and describes what the class does when executed.

>

using System;
class Demo {
   static void Main(string[] args) {
      Console.WriteLine("My first program in C#!");
   }
}
  • public - This is the access specifier that declares that the method is publicly accessible.

  • 01ffcd5d1a840d2341909ced6bafa76cstatic - Here, the object does not need to access static members.
  • void - This indicates that the method does not return any value.

  • main - is As mentioned above, it is the entry point of the C# program, that is, this method is the first method to be executed.

The above is the detailed content of What is the difference between public, static and void keywords in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Final variables in C#Next article:Final variables in C#