Delegate ref/out params, when "real" ref/out isn't legal #6191
Replies: 2 comments 2 replies
-
I feel like this - or something like it - could be useful outside of class Foo
{
int? Num { get; set; }
bool TrySet(string str) => int.TryParse(str, out Num);
} |
Beta Was this translation helpful? Give feedback.
-
I think if a struct that looked like It feels like if you are going to go to the trouble of creating delegates, you might as well just create a reference type to hold the field you want to pass "by reference" and pass that in instead. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For cases where actual
ref
cannot be allowed (async
methods, passing in a property), we declare special structs -Ref<T>
andOut<T>
:Then, we can have this:
The biggest motivation here is nullability analysis. With a custom
Ref<T>
type (which is what I'm doing now in these cases), I can't use the NRT attributes (at least, the ones that are available currently).Beta Was this translation helpful? Give feedback.
All reactions