Before Getting familirised with function overloading we shoul know what a signature of a function is.
Signature of a function
The signature of a function consists of three parts
These three points makes the signature of the function.Signature of a function
The signature of a function consists of three parts
- No of Parameters Used in a function
- Return Type of a Function
- Sequence of the Parameters
Now Coming back to operator overloading...
To understand the concept i would like to ask you a question
- Can you create function having same name???
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
functions_with_same_name
{
class Demo
{
int num1, num2, num3;
void display()
{
Console.WriteLine("THe First Display is called ");
}
void display()
{
Console.WriteLine("This is display 2 and the given values are");
}
static void Main(string[] args)
{
Demo d1 = new Demo();
d1.display();
d1.display();
Console.ReadLine();
}
}
}
using
System; using System.Collections.Generic; using System.Linq; using System.Text; namespace functions_with_same_name {
class Demo {
int num1, num2,num3; void display(int i,int j) {
num1 = i;
num2 = j;
Console.WriteLine("THe First Display is called and The given value is {0},{1} ",num1,num2); }
void display(int i,int j,int z) {
num1 = i;
num2 = j;
num3 = z;
Console.WriteLine("This is display 2 and the given values are {0},{1},{2}",i,j,z); }
static void Main(string[] args) {
Demo d1 = new Demo(); d1.display(4,5);
d1.display(5,6,7);
Console.ReadLine(); }
}
}
and the output is
So what was the diffrence between both the programs
The no of parameters given to the functions
So i want you to guess what is a construtor overloading.To understand the construtors refer to my construtors blog
http://sasiprogramming.blogspot.in/2012/05/constructors-and-destructors.html
I am giving you the demo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace construtor_overloading
{
class DateTime
{
int day, month, year, hrs, min;
DateTime(
int d, int n, int y, int h, int mi)
{
day = d;
month = n;
year = y;
hrs = h;
min = mi;
Console.WriteLine("Todays Date is {0}/ {1}/ {2} and Time is {3}: {4}", day, month, year, hrs, min);
}
DateTime(
int d, int n, int y)
{
Console.WriteLine("Todays Date is {0}/ {1}/ {2}", d, n, y);
}
DateTime(
int h, int m)
{
Console.WriteLine("Time Is {0} :{1}", h, m);
}
static void Main(string[] args)
{
DateTime d1 = new DateTime(26, 05, 2012);
DateTime d2 = new DateTime(26, 05, 2012, 04, 15);
DateTime d3 = new DateTime(04, 15);
Console.ReadLine();
}
}
}
AND THE OUTPUT IS