-
ref struct is supposed to live only on stack and unmanaged. ref struct CanReturnRef
{
public CanReturnRef( int i ) => this.i=i;
private int i;
public int Value=> i;
public ref CanReturnRef Next()
{
i++;
return ref this;
}
}
{
Print( new CanReturnRef(0).Next().Next().Next().Value );//output 3
var fluent = new CanReturnRef(0);
fluent.Next().Next().Next();
Print(fluent.Value);//output 1 which is not expected, but can be fixed by return ref this.
} |
Beta Was this translation helpful? Give feedback.
Answered by
svick
Oct 22, 2020
Replies: 2 comments 1 reply
-
See also: #1997 |
Beta Was this translation helpful? Give feedback.
1 reply
-
There is already a proposal that will allow you to do this. As far as I can tell, the championed issue for that is #1147. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
svick
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is already a proposal that will allow you to do this. As far as I can tell, the championed issue for that is #1147.