logo
CSharp_Prog_Guide

Общие сведения об операторах преобразования

Операторы преобразования обладают следующими свойствами.

Using Conversion Operators

Conversion operators can be explicit or implicit. Implicit conversion operators are easier to use, but explicit operators are useful when you want users of the operator to be aware that a conversion is taking place. This topic demonstrates both types.

Example 1

Description

This is an example of an explicit conversion operator. This operator converts from the type Byte to a value type called Digit. Because not all bytes can be converted to a digit, the conversion is explicit, meaning that a cast must be used, as shown in the Main method.