using System;
namespace HelloWorld
{
class Program
{
static void Main (string[] args)
{
short a = 2000, b = 4000;
int c = Add(a, b);
Console.WriteLine("c = {0}", c);
Console.ReadLine();
}
static int Add(int a, int b)
{
return a + b;
}
}
}
c = 6000
using System;
namespace HelloWorld
{
class Program
{
static void Main (string[] args)
{
short a = 20000, b = 20000;
short c = Add(a, b);
Console.WriteLine("c = {0}", c);
Console.ReadLine();
}
static int Add(int a, int b)
{
return a + b;
}
}
}
short c = (short)Add(a, b);
c = -25536
try
{
short c = checked((short)Add(a, b));
Console.WriteLine("c = {0}", c);
}
catch (OverflowException ex)
{
Console.WriteLine(ex.Message);
}
unchecked
{
short c = (short)Add(a, b);
Console.WriteLine("c = {0}", c);
}