Search code examples
c#compiler-warningsreference-type

The given expression is always of the provided type


Why does Visual Studio warn about this when using is on value types, but doesn't when on reference types? Lines 1 and 2 raise the warning, while lines 3 and 4 don't.

if (5 is object)
if (new Point() is object)

if ("12345" is object)
if (new StringBuilder() is object)

Solution

  • Because it was not implemented by Microsoft. But it is e.g. implemented by JetBrains ReSharper.

    Visual Studio shows 2 compiler warnings:

    Visual Studio

    ReSharper shows 4 warnings:

    ReSharper