In addition to what Wayne explains:
The keyword
out
also says that the parameter
should change the value in the method implementation. The code sample below shows that constraint and explains essential difference between ref and
out
; both modes are by-reference:
struct MyStructure { }
struct SomeType {
void SomeMethod(ref MyStructure reference) { }
void SomeBadMethod(out MyStructure reference) { }
void FixedMethod(out MyStructure reference) {
out = new MyStructure();
}
}
[EDIT]
Also, a calling code is not required to initialize a variable used as
out
parameter (as it will be initialized as a result of the call).
—SA