How to return a named tuple with only one field
10
I wrote a function in c# which initially returned a named tuple. But now, I only need one field of this tuple and I would like to keep the name because it helps me to understand my code.
private static (bool informationAboutTheExecution, bool field2thatIdontNeedAnymore) doSomething() {
// do something
return (true, false);
}
This function compile. But It's the following function that I want
private static (bool informationAboutTheExecution) doSomething() {
// do something
return (true);
}
the error messages:
Tuple must containt at least two elements
cannot implcitly convvert type 'bool' to '(informationAboutTheExecution,?)
Has somebody a solution to keep the name of the returned value?
c#
out
parameter instead... – Sweeper Apr 8 at 13:25DoSomethingResult
class or struct and return that instead and then just update it whenever you need to return more values. You can even add deconstruction to it so that it will be similar to a value tuple. – juharr Apr 8 at 13:36