What if your methods could tell you exactly what they did, instead of leaving you guessing?
Why Return values and void methods in C Sharp (C#)? - Purpose & Use Cases
Imagine you are baking cookies and writing down each step on paper. After baking, you want to know how many cookies you made, but you only wrote the steps, not the result.
Without a way to get results back, you must guess or check manually. This wastes time and can cause mistakes, especially if you repeat the process many times.
Return values let methods give back results, like telling you exactly how many cookies you baked. Void methods do tasks without returning anything, like just baking without counting.
void BakeCookies() { /* bake but no count returned */ }
int count = 0; // manual tracking outsideint BakeCookies() { /* bake and return count */ return 12; }It lets your program communicate results clearly, making code easier to use and understand.
A calculator method returns the sum of two numbers so you can use it elsewhere, while a void method might just print a message without returning anything.
Return values send results back from methods.
Void methods perform actions without returning data.
Using both properly makes programs clearer and more powerful.