Function Overloading in c#.
In C# the significance of the function must vary from each other by the types and/or the number of arguments .A single function or method can have different nature based on number of parameters and types of parameters.You cannot overload function declarations that vary only by return type.
using System;
Example=1.
namespace FunctionOverloading
{
class Printvalue
{
void show(int A)
{
Console.WriteLine("Printing int value: {0}", A);
}
void show(double B)
{
Console.WriteLine("Printing value float: {0}", B);
}
void show(int C, int D)
{
Console.WriteLine("Printing int value: {0},{1}", C, D);
}
void show(string H)
{
Console.WriteLine("Printing string data: {0}", H);
}
static void Main(string[] args)
{
Printvalue p = new Printvalue();
p.show(38);
p.show(32,19);
p.show(200.800);
p.show("Hello C# language");
Console.ReadKey();
}
}
}
2. Function Overloading example..
using System;
namespace F_overloading
{
class Program
{
static void Main(string[] args)
{
Cal.add();
Cal.add(15, 45);
Cal.add(13.3f, 3.6f);
Cal.add("Hello C#");
Console.Read();
}
}
static class Cal
{
public static void add()
{
Console.WriteLine("No Value are= ");
}
public static void add(int a, int b)
{
Console.WriteLine("add of {0} and {1} is {2}", a, b, (a + b));
}
public static void add(float a, float b)
{
Console.WriteLine("add of {0} and {1} is {2}", a, b, (a + b));
}
public static void add(string s)
{
Console.WriteLine("{0} - string value", s);
}
}
}
using System;
Example=1.
namespace FunctionOverloading
{
class Printvalue
{
void show(int A)
{
Console.WriteLine("Printing int value: {0}", A);
}
void show(double B)
{
Console.WriteLine("Printing value float: {0}", B);
}
void show(int C, int D)
{
Console.WriteLine("Printing int value: {0},{1}", C, D);
}
void show(string H)
{
Console.WriteLine("Printing string data: {0}", H);
}
static void Main(string[] args)
{
Printvalue p = new Printvalue();
p.show(38);
p.show(32,19);
p.show(200.800);
p.show("Hello C# language");
Console.ReadKey();
}
}
}
2. Function Overloading example..
using System;
namespace F_overloading
{
class Program
{
static void Main(string[] args)
{
Cal.add();
Cal.add(15, 45);
Cal.add(13.3f, 3.6f);
Cal.add("Hello C#");
Console.Read();
}
}
static class Cal
{
public static void add()
{
Console.WriteLine("No Value are= ");
}
public static void add(int a, int b)
{
Console.WriteLine("add of {0} and {1} is {2}", a, b, (a + b));
}
public static void add(float a, float b)
{
Console.WriteLine("add of {0} and {1} is {2}", a, b, (a + b));
}
public static void add(string s)
{
Console.WriteLine("{0} - string value", s);
}
}
}

0 Comments