Will ValueTuples make out parameters obsolete? [closed]
Asked Answered
G

0

7

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?

Glassworker answered 19/1, 2017 at 14:49 Comment(9)
ref and out are still useful for interop.Fairy
There's also a lot of existing code that uses out parameters. Dictionary.TryGetValue() isn't going anywhere, for example.Selfabasement
ref and out are stackpointers!Gailgaile
This very similar question was closed as opinion based, I think this one probably will be too.Fission
i think i'd still opt for an out parameter for any try-parse type routines, which is about the only place I use themPsychodiagnostics
@Fission The question got two close votes already for that reason, I'm not sure I understand why, though.Glassworker
@TimPohlmann How isn't it opinion based? What fact is there in the answer to "do you think feature X is useful?"Agretha
There's no technical reason why tuples would make out 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
@Fission I clarified the question now.Glassworker

© 2022 - 2024 — McMap. All rights reserved.