I need to understand the meaning of !is
in c#. I understand the is
keyword. I expected that a !is b
would be the same as !(a is b)
.
However, after testing, I found out that this is not the case. I just need to know what it means and when it may be useful.
I have checked the documentation for is.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/is
From the navigation, it appears the only type testing keyword is is
. There's no obvious reference to !is. I can find none in the same page as is, yet the compiler doesn't fail when I use !is. (Is this a bug?).
previousStageResult.Data is defined as object.
// this
var previousResultIsInvalid = previousStageResult.Data !is Dictionary<string, int>;
// returns the same thing as
var previousResultIsInvalid = previousStageResult.Data is Dictionary<string, int>;
// What I expect:
var previousResultIsInvalid = previousStageResult.Data !is Dictionary<string, int>;
// should be the same as
var previousResultIsInvalid = !(previousStageResult.Data is Dictionary<string, int>);
// if it is even valid at all
Thank you.