Of course, this is not only a problem for Guid . The same behavior is observed with any type of struct that is not a predefined type of C #, provided that struct overloads operator == usual way. Other examples within the framework include DateTime and TimeSpan .
This deserves a warning about compilation time, since being technically legal due to a raised statement, this is not useful since it always gives false . Thus, this indicates a programmer error.
As Eric Lippert said in his answer, the compile-time compiler existed along with the Visual C # 2.0 compiler. In versions 3.0 through 5.0, a warning was accidentally omitted (for these "user-defined" struct types, but not for predefined value types such as int , and not for enumeration types).
Since C # 6.0 (based on Roslyn), the compiler again detects this code problem. However, due to backward compatibility (!), A warning is not issued if you do not compile your code with the so-called strict function.
To enable strict mode, when you use the .csproj file (in most cases), unload the project from Visual Studio, edit the file, insert the XML element:
<Features>strict</Features>
in each <PropertyGroup> (usually there will be more than one) of the .csproj file. Then you get a warning (it can be βadvancedβ to an error if you use the Warning warning as an error).
If you cannot edit .csproj , and if you call msbuild.exe from the command line to compile, use the switch:
/p:Features=strict
to msbuild.exe .
If you are not using .csproj files because you are compiling directly with csc.exe (C # compiler), use the switch:
/features:strict
to csc.exe on the command line.
Jeppe Stig Nielsen Dec 09 '16 at 21:23 2016-12-09 21:23
source share