csharp / beginner
Snippet
Defining Basic Methods
Methods are blocks of code that perform a specific task. They help organize code and make it reusable. 'void' means the method does not return a value.
snippet.csharp
1
2
3
4
5
void GreetUser(string name) {Console.WriteLine("Hello, " + name + "!");}GreetUser("Alice");
Breakdown
1
void GreetUser(string name)
Defines a method named GreetUser that takes one string parameter.
2
Console.WriteLine(...);
The logic inside the method that uses the parameter.
3
GreetUser("Alice");
Calls (executes) the method with the argument "Alice".