With the introduction of ValueTuples in C# 7.0 we can now have multiple return values:
public (int sum, int count) GetTallies()
{
return (1, 2);
}
I'm under the impression that the sole reason for out
parameters is to provide a workaround for the restriction of having only one return value. However, out
parameters are getting improved as well which says to me that the C# designers don't think they will become obsolete.
Am I missing something or is the reason for the introduction of the out var declaration
just to ease the use of older libraries?
To clarify the question a bit more: Is there anything I can do with out
, I cannot do with ValueTuples
?
ref
andout
are still useful for interop. – FairyDictionary.TryGetValue()
isn't going anywhere, for example. – Selfabasementout
parameter for any try-parse type routines, which is about the only place I use them – Psychodiagnosticsout
parameters obsolete, to the point where you should use them instead, so it's more down to whether people will use them, ergo it's opinion. – Guevara