Function overloading means "function with same name but different no of parameters. In this if we have same no of parameter on that case datatype must be different. In this article i have used example of c#.net.
Here i will show you an example of function overloading.
In above code you can check that in class MethodOverloading i have keep the method name same but differ with the passed parameter. Now check the output.
Here i will show you an example of function overloading.
using System;
namespace
ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
MethodOverloading
methodoverloading = new MethodOverloading();
Console.WriteLine(methodoverloading.DiplayData(111));
Console.WriteLine(methodoverloading.DiplayData(1,
2));
Console.WriteLine(methodoverloading.DiplayData(1.1f,
1.1f));
Console.ReadLine();
}
}
public class MethodOverloading
{
public string DiplayData(int val1)
{
return "Passed Value= "
+ val1;
}
public string DiplayData(int val1, int val2)
{
return ("Sum=" +
val1 + val2);
}
public string DiplayData(float val1, float val2)
{
return ("Sum=" +
(val1 + val2));
}
}
}
|
0 comments:
Please let me know your view