-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Champion "conditional ref operator" (C# 7.2) #223
Comments
@DavidArno - this was discussed: The proposal predates dotnet/csharplang, so it has not been moved to this repo yet. |
Ah cool, thanks. |
There is also a PR with implementation. - It is a relatively small feature. Basically a left over from the "ref returns". |
@DavidArno This feature appeared in literally every example in the original feature request for ref locals and ref returns, but wasn't included in C# 7 along with the feature. |
(array1 == null ? ref array1[index] : ref dummy) = value; Shouldn't it be |
How about null-conditional expressions, e.g. |
@yaakov-h I don't understand your proposal, but in any case it is certainly a different feature request than this one. If you're requesting a different feature please open a new issue for that. |
Can we do this instead? ref (array1 != null ? array1[index] : dummy) = value;
ref Node next = ref (node != null ? node.Next : head); |
@alrz - it would imply that That is easily observable if the expression returns a struct and you call a mutating method on it - If the expression is supposed to be an LValue only as a part of ref assignment, then there is a need for more rules to figure when ternary is an LValue and when it is not, while being very careful with compat. And that is only to save typing one |
I'm proposing that ref (e1 ?? e2)
ref (e match { case P1: e1; case P2: e2; default: e3; })
ref (e1 ? e2 : e3) Repeating |
It’s here now: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/conditional-ref.md It should probably be moved and re-tagged since it’s missed the 7.2 release. |
The feature is a part of 7.2 The up-to date description is a part of: |
Ah. Should this be closed as a duplicate, then? 😁 |
It seems that this does not play nicely with throw-expressions. public ref T this[int index] => index == 0 ? ref _thing : throw new IndexOutOfRangeException(); This isn't super critical but it does save typing compared to an explicit Apologies if this is not the right place to post this. |
@svick - somehow did not find that when searching, thanks for the response. |
(https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/conditional-ref.md)
See also
https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md
The idea would be to support a version of the
?:
operator that yields an lvalue. The current proposal is to do so usingref
after the:
and?
, for exampleThe text was updated successfully, but these errors were encountered: