Conversion Operations

It is often necessary to convert between types. The conv instruction casts between primitive types. The instruction has a single operand, which is the destination type of the cast. A conversion can cause an overflow when the memory size of the source is larger than the target. For example, this could happen when casting from a 64-bit integer to a 32-bit integer. The high-order bits are trimmed when an overflow occurs, which naturally changes the normal results. It’s important to note that when overflows are ignored, subtle bugs are possible. The conv.ovf instruction prevents an overflow from going undetected. When an overflow occurs, an overflow exception is raised.

The following code contains an overflow condition, where ...

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.