|
-
Jul 18th, 2022, 04:33 AM
#2
Re: unexpected behavior with ctype and nullable byte (byte?) variable
The If operator that you're using is effectively generic, in that the two potential return values must be the same type or one must be a type derived from the other. In your first code snippet, you have this:
so that If operator is returning a String, i.e. either a null reference of type String or the value of s. The CType operator is then converting that String reference to a Byte? and it appears that the result of using CType to convert a null String reference to a nullable numeric type is always zero. I tried it with Integer? as well and got the same result. In the second case, because the last argument to If is type Byte?, the second argument is inferred to be that type too, so that Nothing is going directly to type Byte?, rather than to String first and then to Byte?. It seems to be a bit of an idiosyncratic behaviour but it is what it is.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|