Parameters & Returns in C#
From the C# Programming Language cheat sheet · Methods (Functions) · verified Jul 2026
Parameters & Returns
Advanced parameter passing
csharp
// Pass by value (default)
void ChangeValue(int x)
{
x = 100; // Doesn't affect original
}
// Pass by reference
void ChangeRef(ref int x)
{
x = 100; // Changes original
}
// Out parameters (must assign)
bool TryParse(string input, out int result)
{
return int.TryParse(input, out result);
}
// Multiple returns with tuples
(int sum, int product) Calculate(int a, int b)
{
return (a + b, a * b);
}
// Named arguments
PrintInfo(age: 25, name: "Bob");💡 ref modifies original, out returns multiple values
⚡ params allows variable number of arguments
📌 in parameters for read-only reference passing
🟢 Tuples are great for returning multiple values