I was testing a simple program to overload integer parameters:
class Program
{
public static void Foo(Int16 value)
{
Console.WriteLine("Int16");
}
public static void Foo(Int32 value)
{
Console.WriteLine("Int32");
}
public static void Foo(Int64 value)
{
Console.WriteLine("Int64");
}
static void Main(string[] args)
{
Foo(10);
}
}
Now I know that the capacity of these types is this:
Type Capacity
Int16 -- (-32,768 to +32,767)
Int32 -- (-2,147,483,648 to +2,147,483,647)
Int64 -- (-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807)
Now Foo(10)
calls the Int32
overload. Why? Can't the value of 10 fit in an Int16
?
What confuses me more, is that when I remove the Int32
overload, the Int16
overload is called. Why is that?