May 2010
Intermediate to advanced
1752 pages
41h 17m
English
Now that you understand how to interact with intrinsic C# data types, let's examine the related topic of data type conversion. Assume you have a new Console Application project named TypeConversions that defines the following class:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("***** Fun with type conversions *****");
// Add two shorts and print the result.
short numb1 = 9, numb2 = 10;
Console.WriteLine("{0} + {1} = {2}",
numb1, numb2, Add(numb1, numb2));
Console.ReadLine();
}
static int Add(int x, int y)
{ return x + y; }
}
Notice that the Add() method expects to be sent two int parameters. However, the Main() method is, in fact, sending in two short variables. While this ...