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

王林
Release: 2023-11-21 16:47:35
forward
1728 people have browsed it

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#!");
   }
}
Copy after login
  • public - This is the access specifier that declares that the method is publicly accessible.

  • < p>static - 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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!