Why is Visual Studio saying this cast from System.Int32 to System.Byte is redundant?

117 Views Asked by At

I'm trying to retrieve a type of Byte for a unit test, yet when I do a simple cast as shown below, I get the code analysis info in VS that the cast is redundant. Why? Clearly the cast is needed to keep the result from returning System.Int32 instead of System.Byte.

enter image description here

1

There are 1 best solutions below

0
roten On

I'm not sure, but my best guess is that because the value you want to cast is compile-time known it let's you know that semantics will be the same. That is true as long you don't use reflection to get type info.