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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pranshu SinghalPosted Jul 10, 2025, 7:00 AM
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.
Abhishek YadavPosted Jul 11, 2025, 10:17 AM
Static do net requires any refrence
Public Acessable across the application and assambly
void returns nothing
Jack QasimPosted Jul 11, 2025, 6:41 AM
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.
Cynthia SathuragiriPosted Jul 10, 2025, 6:38 AM
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.
Mukul SinghPosted Jul 9, 2025, 7:01 AM
Here is the Key difference
Public is an access modifier.publicmeans the method is accessible from anywhere, even outside the class or assembly.Rajanikant HawaldarPosted Jul 5, 2025, 2:04 PM
https://www.c-sharpcorner.com/interview-question/what-is-the-difference-between-public-static-and-void