-
Recently bumped into an interesting problem (?) with object comparison:
Is this an issue or a design decision? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes it's the how it's designed
|
Beta Was this translation helpful? Give feedback.
-
From the documentation: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator
It also lists all of the cases in which the operands are considered compatible. |
Beta Was this translation helpful? Give feedback.
Yes it's the how it's designed
obj is ReadOnlyBytes
can be seen as ifobj
can be assigned to a variable of typeReadOnlyBytes
if (obj is ReadOnlyBytes bytes) { /* use bytes here */ }
obj?.GetType() == typeof(ReadonlyBytes)
check ifobj
is exactlyReadonlyBytes