Why doesn’t Visual Studio warn me about cyclic initialization of a static string?

The stupid, but probably not very rare mistake, when I replaced the string literal with a static string, led to something like the following piece of code, which was probably almost never intended and trivial to define even for a machine:

public partial class T { static string S = S; }

This does not cause diagnostics with VS Professional 2013, .NET Framework 4.6.0.1055, warning level 4. 1 Why not?


1 To be fair with the compiler, I assume that initialization is clearly defined and assigns the value S'in its state to default values ​​before explicit initialization, that is, null, to itself when initialization is ultimately completed; but it is almost certainly a coding error.
+4
source share
1 answer

Recent versions of Visual Studio say:

Warning CS1717 Assignment assigned to the same variable; did you mean to appropriate something else?

So ... update your IDE :)

+6
source

All Articles