[c# 7.3] cannot pass this with in? Seems like you should #2129
Replies: 7 comments
-
The code |
Beta Was this translation helpful? Give feedback.
-
Yes, it will compile if you remove Either way, being able to put |
Beta Was this translation helpful? Give feedback.
-
No, because either way the variable is passed by Also, passing by public void MapObjectB(B obj)
{
obj = new B(); //doesn't replace the instance that was passed at the call-site
} Moreover, using |
Beta Was this translation helpful? Give feedback.
-
My purpose for putting |
Beta Was this translation helpful? Give feedback.
-
It doesn't mean that you are using it a readonly fashion however. You end up with a double indirection (effectively a This is in contrast to a value type passed by |
Beta Was this translation helpful? Give feedback.
-
Why would you use |
Beta Was this translation helpful? Give feedback.
-
I was playing around and trying to communicate the intent of "i'm treating what you pass me as readonly". I just thought I would raise this issue as it felt odd to me. We can just close it as it seems it's not really a big deal nor really a bug. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
@Thraka commented on Tue Jan 08 2019
Version Used: 7.3
Steps to Reproduce:
Expected Behavior:
I could use
in this
asthis
is passed within
, it is read-only and not assignable.Actual Behavior:
Error that you cannot pass
this
byref
@gafter commented on Tue Jan 08 2019
The compiler is correct.
this
is a value, not a variable. Nevertheless, this is a reasonable feature request so I'm moving it tocsharplang
.Beta Was this translation helpful? Give feedback.
All reactions