I was playing with function overloading in C#. The below code made me to realize that double datatype can accommodate float value:
class program
{
static void Main(string[] args)
{
test(2f);
Console.Read();
}
static void test(double a)
{
Console.WriteLine("double called" + a);
}
}
Same as above code, i also found that float can accommodate int value. Double can accommodate int and float both values.
First i thought it is due to the range of the datatypes.
But decimal changed my thought as below code is not compiling:
class Program
{
static void Main(string[] args)
{
test(2d); //Invalid argument error
Console.Read();
}
static void test(decimal a)
{
Console.WriteLine("decimal called" + a);
}
}
Why decimal datatype can not accommodate float and double values, whereas double datatype can accommodate float value and float datatype can accommodate int value?