Back to course

Method Parameters and Return Values

.NET Zero to Hero: Master C# and Modern App Development

Passing and Returning Data

Parameters:

Variables passed into the method. csharp static void Greet(string name) { Console.WriteLine("Hello " + name); }

Return Values:

If you want the method to return a result, change void to a data type. csharp static int Add(int x, int y) { return x + y; }

// Usage int result = Add(5, 3);