C# Return Values

C# Return Values

In C#, a return value is the data that a method sends back to the caller after it finishes execution. Methods that return values must specify a return type.


🔹 Basic Return Value


Calling the Method



🔹 Method Returning a String



🔹 Method Returning Boolean



🔹 Return Multiple Values (Using out)



🔹 Return Multiple Values (Tuple – Recommended)



🔹 Return an Array



🔹 Return Object



🔹 return Ends Method Execution


 


🔹 Void Methods (No Return)



🔹 Common Mistakes

❌ Missing return statement
❌ Returning wrong data type
❌ Code after return (unreachable)


🔹 Summary

✔ Methods can return values
✔ Return type must match value
return stops execution
✔ Use tuples for multiple values

You may also like...