Can I ignore a single return value when multiple values are returned?
Some time ago, the ability to create a function which has multiple return values was created. Yes, I know this can be avoided by using out… but I was curious. In traditional method calls, the return value can be ignored by not assigning the return value to a variable. I recently decided to use multiple return values in a new method because I wanted to avoid having to worry about the method call when the return value isn’t always used. Turns out that may have been an oversight on my part, since I as far as I know, I still have to define a return value. For example, if the return signature of “MyFunction” is (int, bool) and I don’t need the bool value, I still have to define it (FAIK… which is the point here):
private (int, bool) MyFunction(…)
{
bool error = false;
int someReturnValue = 0;
//… does something and sets error if there is a problem
return (someReturnValue, error);
}
public void MyUnconcernedCallerFunction()
{
int ret;
bool error; // what if I don’t need to worry about the error here?
(ret, error) = MyFunction(…);
}
is there currently any convention that allows me to not declare the bool error value if I don’t need it? (i.e. can I ignore the bool part of the return?)
SIDE NOTE: Why isn’t there a general forum here? While my example is language specific, the question isn’t. This is just a general .NET question having to do with data and there are no general options in the “Choose a Label” options. I couldn’t post without choosing one so I just picked the one that made the most sense.
Some time ago, the ability to create a function which has multiple return values was created. Yes, I know this can be avoided by using out… but I was curious. In traditional method calls, the return value can be ignored by not assigning the return value to a variable. I recently decided to use multiple return values in a new method because I wanted to avoid having to worry about the method call when the return value isn’t always used. Turns out that may have been an oversight on my part, since I as far as I know, I still have to define a return value. For example, if the return signature of “MyFunction” is (int, bool) and I don’t need the bool value, I still have to define it (FAIK… which is the point here): private (int, bool) MyFunction(…)
{
bool error = false;
int someReturnValue = 0;
//… does something and sets error if there is a problem
return (someReturnValue, error);
}
public void MyUnconcernedCallerFunction()
{
int ret;
bool error; // what if I don’t need to worry about the error here?
(ret, error) = MyFunction(…);
} is there currently any convention that allows me to not declare the bool error value if I don’t need it? (i.e. can I ignore the bool part of the return?) SIDE NOTE: Why isn’t there a general forum here? While my example is language specific, the question isn’t. This is just a general .NET question having to do with data and there are no general options in the “Choose a Label” options. I couldn’t post without choosing one so I just picked the one that made the most sense. Read More