What is the difference between static, public, and void in C# dotnet
Loading
What is the difference between static, public, and void in C# dotnet
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pranshu SinghalRank #1,969 · 744 reputationPosted Jul 10, 2025, 3:00 AM EDT
1. Static: The
statickeyword in C# is used to declare a member (method, property, field, or event) as belonging to the type itself, rather than to a specific instance of the type. Also, static members can be accessed without creating an instance of the class.2. Public: The
publicaccess modifier in C# is used to allow access to a member (class, method, property, field, or event) from anywhere in your code. Public members can be accessed from within the class, as well as from outside the class.3. Void: The
voidkeyword in C# is used to indicate that a method does not return a value. When a method is declared asvoid, it means that the method will not return any data back to the caller.I hope this helps you clarify.
Mukul Singh35 reputationPosted Jul 9, 2025, 3:01 AM EDT
Here is the Key difference
Public is an access modifier.publicmeans the method is accessible from anywhere, even outside the class or assembly.public void Greet() { Console.WriteLine("Hello!"); }public static void ShowTime() { Console.WriteLine(DateTime.Now); }public void PrintName(string name) { Console.WriteLine("Name is: " + name); }Cynthia SathuragiriRank #937 · 2.2K reputationPosted Jul 10, 2025, 2:38 AM EDT
public :The method or variable is accessible from anywhere, including other classes.public int Add(int a, int b) { return a + b; }Here the method can be called from outside the class because it is marked as
public.static :Belongs to the class itself, not to an instance (object) of the class.public static void Greet() { Console.WriteLine("Good morning!"); }Here you can call
Greet()without creating an object of the classProgram.Greet();void: The method does not return any value.public void ShowMessage() { Console.WriteLine("Sample message."); }The method prints something but doesn’t return anything.
Jack Qasim17 reputationPosted Jul 11, 2025, 2:41 AM EDT
Quotes About Hard Work:
Dreams don’t work unless you do.
Static means the method belongs to the class, not objects.
Public means it is accessible from anywhere.
Void means it returns nothing.
Abhishek YadavRank #217 · 11.3K reputationPosted Jul 11, 2025, 6:17 AM EDT
Static do net requires any refrence
Public Acessable across the application and assambly
void returns nothing
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Jul 5, 2025, 10:04 AM EDT
https://www.c-sharpcorner.com/interview-question/what-is-the-difference-between-public-static-and-void