Well here is my picture:
Method 1
This is a type, that is, the value must be of a type, which can be in an explicit or explicit conversion to bytes. In addition, the value must not go beyond the byte.
The call fails because the compiler does not have any information about what type of object it should use, and therefore cannot perform an implicit or explicit conversion. Performance
int obj = 1; byte b = (byte) obj;
or
byte b = (byte) (int) obj;
works. The second option uses expack unboxing (thus providing the necessary information), as described in a comment and publication by Reed Copsey. The link provided by Reed Copsi's comment explains this in detail.
For sampling user objects, the use of implicit and explicit conversions are statements that are static methods defined in the class. For object there are no explicit or explicit operations (see the link for the reason why), while for int these operations exist.
Method 2
Here you parse the string, the string value must be a number that is inside the byte boundary. Here you can also use TryParse , which allows you to check if the conversion is successful.
Method 3
Uses the type conversion of the Convert class. This is the most flexible method supporting most common types. Here, the value must be converted to a number, and the value must be inside the byte bounds. The Convert class uses IConvertible to convert between different types and is therefore extensible.
source share