Search code examples
.netc#-4.0resharperc#-5.0fxcop

Does .net 5 compiler give warning for the loop-variable-closure issue?


I am currently working on a big project which uses .net 4 and in a few months we'd soon be moving to .net 5. I am wondering if .net 5 compiler gives warning to the loop-variable-closure issue? Other than resharper does fxcop/.net-5-compiler give warning to this?

The reason i am asking this is because i am afraid there will be a breaking change if we move our code base to .net 5, so wondering if there is a way (compiler, fxcop etc) to tell in advance that this might be an issue. I do not have resharper thus i ruled it out (better have support in the base tools)


Solution

  • It seems you are confusing C# versions and .Net versions. The latest .Net version is 4.5 and the latest C# one is 5.0.

    The breaking change fix only exists in C# version 5.0 and it only affects the foreach loop. As Console explained you would only need to worry about it if you were relying on that bug being there, which isn't likely. You can however safely use the latest .Net with an old C# version (i.e. 4.0).

    If you do end up using C# version 5.0 you won't get a warning, because there's nothing to warn about anymore. The bug was fixed, even though it was a small breaking change.