O'Reilly logo

Microsoft® Visual C#® 2008 Step by Step by John Sharp

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding Conversion Operators

Sometimes it is necessary to convert an expression of one type to another. For example, the following method is declared with a single double parameter:

class Example
{
    public static void MyDoubleMethod(double parameter)
    {
        ...
    }
}

You might reasonably expect that only values of type double could be used as arguments when calling MyDoubleMethod, but this is not so. The C# compiler also allows MyDoubleMethod to be called with an argument whose type is not double, but only as long as that value can be converted to a double. The compiler will generate code that performs this conversion when the method is called.

Providing Built-In Conversions

The built-in types have some built-in conversions. For example, an int can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required