In overloading functions it is possible to have functions with similar names that perform differently so long as the parameters are different. Is it possible to have different return type too? for instance in the code below
**************************
**********
**********
**********
**********
**********
**********
**********
**********
******
public class MyClass
{
public void AFunction()
{
Console.WriteLine("AFuncti
on() has been called");
}
public static void AFunction(int a)
{
Console.WriteLine("AFuncti
on(int a) has been called");
}
public static void AFunction(double d)
{
Console.WriteLine("AFuncti
on(double d) has been called");
}
}
public static void Main(string[] args)
{
AFunction();
AFunction(1);
AFunction(2.0);
}
**************************
**********
**********
**********
**********
**********
**********
**********
**********
*********
As far as function overloading is concerned, can I change the AFunction functions such that they have different return type and call the desired one by passing the corresponding parameters as shown below?
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
****
public class MyClass
{
public void AFunction()
{
Console.WriteLine("Void");
}
public int AFunction(int a)
{
return 1;
}
public double AFunction(double d)
{
return 2.4;
}
}
public static void Main(string[] args)
{
AFunction();
int x = AFunction(1);
double y = AFunction(2.0);
}
**************************
**********
**********
**********
**********
**********
**********
**********
**********
**********
Thanks in advance
a_anis3000
Start Free Trial