■
Note
Look up the topic “Type Conversion Tables” within the .NET Framework 3.5 SDK documentation if you
wish to see permissible widening conversions for each C# data type.
Although this implicit widening worked in our favor for the previous example, other times this
“feature” can be the source of compile-time errors. For example, assume that you have set values
to numb1 and numb2 that (when added together) overflow the maximum value of a short. As well,
assume you are storing the return value of the Add() method within a new local short variable,
rather than directly printing the result to the console:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with type conversions *****");
Do'stlaringiz bilan baham: |