-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Reference types can be passed in
#23327
Comments
In theory it's not without benefit. Perhaps Also, this applies to primitive types as well. There's little reason to pass an
That would make the whole thing rather useless. You won't be able to invoke any method on |
So you can do this? public class C
{
static MyClass v = new MyClass();
public class MyClass
{
public int Value { set; get; }
}
static void Thing(in MyClass c)
{
Console.WriteLine(c.Value);
c.Value = 5;
Console.WriteLine(c.Value);
Thing();
Console.WriteLine(c.Value);
}
static void Thing()
{
v = new MyClass();
}
static void Main()
{
Thing(in v);
}
} And output
That's terrifyingly leaky... |
I suppose it is doing what it says... Maybe it just needs a "wtf are you doing" warning squiggle |
It certainly is and I can't think of a real world example that would justify using Anyway, the more I look at this the more convinced I am that the issue is the keyword choice - |
I can only see it being useful in a multi-threaded scenario; except it doesn't have the guarantees needed for that... |
Sure it's not useful but it's there for completeness with |
Judging by the confusion it seems to cause I'd say that it's worth it. |
Who's confused? |
Some examples: |
Hmm... I'd say that's just people forgetting that |
That's true but the current implementation still looks like it's asking for trouble without providing significant benefits. There is a combination of factors that I think make
To me that's an additional argument for keeping only
If you look at it like this then |
Version Used:
7.2
Steps to Reproduce:
Expected Behavior:
Either doesn't compile (is a de-optimization as its a double dereference; for no benefit)
Or prevents
.Value
being assigned (as perstruct
)If 2. then it should stay as reference passed by-value but just be a compiler check; rather than reference passed by-reference.
Actual Behavior:
Compiles fine; passes by reference and allows the assignment.
The text was updated successfully, but these errors were encountered: