The out keyword causes arguments to be passed by reference. This is like the ref keyword, except that ref requires that the variable be initialized before it is passed
in: MSDN C# Development Center
This post objective is to point out 4 reasons why you shouldn’t use this keyword in your regular C# programming:
It obligates the programmer to make code around it’s usage. Example: if you want to call a method with an out keyword, you must declare a variable first.
Now imagine you decide that the method should have 5 more parameters? And you think: “If i have one, i can have 5 more”. Now you have to declare 6 variables before the method, insert 6 variables into the method signature, and the obligation to set the variable before the end of the method.
it’s the diference between this:
int var1; int var2; int var3; int var4; int var5; int var6; Something(out var1,out var2,out var3,out var4,out var5,out var6);
and this,
MyObject obj = Something();
Methods that have outs in the signature are more dificult to use than the ones that don’t use them(see the code above).
One of the things that i hate are signatures of methods that have 5 or 6 out parameters and, from those 5 or 6 i only want to use 2 of them (for example).
In those cases, i am always obligated to declare the 6 variables, because we really need to pass all of them to the method. If a return object/struct is used, this problem doesn’t apply.
It’s Syntax! Ugly until the end… Yes is easy to use, but it makes unreadable code… Especially because most of the programmers use and abuse of it.
“How will i return this values? humm, making a nested struct or class is so dificult!!!!! I’ll just use the out keyword”
There is always a way around. If you have more than one return value consider the usage of a struct or a class. The code will be cleaner, more readable and all of your methods will be easier to use by other programmers.