I was messing around with my C# project a little bit and I was surprised to see this code compiles:
var a = new Action<string>(ref b => b = "hello");
Flipping it the other way around, like Action<string> a = ref b => b = "hello";
will give a syntactical error at 'ref'.
Sure enough, copy-pasting the snippet into http://dotnetfiddle.net gives a compiler error:
A ref or out argument must be an assignable variable
Have I encountered a bug in the compiler? (I'm using VS 2015 and C# 6.)
EDIT: Just switched to the Roslyn compiler on .NET Fiddle, it still emits the same error.
It sounds like a compiler bug in VS2015. This is filed as https://github.com/dotnet/roslyn/issues/6646
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With