Optional output parameter in c#

By: Tapkoff Date of post: 20.07.2017

c# - C# optional out/ref arguments - Stack Overflow

I have a method that has several overrides. In one of the more expanded overrides, I want to return an OUT parameter but not in my simpler overrides.

null - C# Optional Out Parameter - Stack Overflow

That looks fine to me. A out cannot be optional for technical reasons it needs to point to a valid instance.

Personally I think it is fine "as is". Another approach, though, is to return a composite return value perhaps an immutable struct with 2 properties ; that avoids the fact that some people avoid out. I am not one of those people: If you wanted to get unnecessarily fancy you could give the conposite return-type a conversion to bool to allow implicit if tests.

optional output parameter in c#

It changes the semantics of what param3 is. The caller still must supply all three arguments. Overloading IsPossible by providing an overload -- the "don't care" scenario -- that discards the reference parameter is the proper solution.

By posting your answer, you agree to the privacy policy and terms of service. Stack Overflow Questions Developer Jobs Documentation beta Tags Users. Sign up or log optional output parameter in c# to customize your list. Tour Free ebook currency trading for dummies here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads optional output parameter in c# us.

Log In Sign Up. Join the Stack Overflow Community. Stack Overflow is a community of 7.

C Programming Tutorial - 56 - Passing Arguments to Functions

Join them; it only takes a minute: Can I or should I use a null-able out parameter? Derek Hunziker 9, 3 41 Having a sarnoff options trader time believing the reason for not supporting this is technical more than marketing priorities.

Seems the compiler could just create a temp location just as your example--and also for Refs by init'ing with Default T. A 'ref' or 'out' parameter cannot have a default value.

Passing optional parameter by reference in c++ - Stack Overflow

The way you've done it is just fine. Sorry, no silver bullet. A nullable out parameter won't do you much good.

Yes, Nullable variables are great. You would then do something like this. Jethro 5, 1 14 I don't find this API style hugely obvious to the caller, personally. What do you mean obvoius to the caller?

optional output parameter in c#

Sign up or log in StackExchange. Sign up using Facebook. Sign up using Email and Password.

c# - Optional Output Parameters - Stack Overflow

Post as a guest Name. Stack Overflow works best with JavaScript enabled. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.

inserted by FC2 system