We'll declare a method that has string and double parameters in this example.
When you overloading methods, the methods will be called based on the
argument's type. A double argument will call the method which gets a "double"
inside it. An integer argument will match with a method which gets a "int" inside it.
Thats the point of the Overloading. Lets see it in example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main()
{
Console.WriteLine("You are in Main Method.");
Console.WriteLine("---");
Enter(5);
Console.WriteLine("---");
Enter(5.2);
Console.WriteLine("---");
New("A text here. The number is:", 666);
}
static void Enter(int n)
{
Console.WriteLine("You are in Enter Method with INT parameter");
Console.WriteLine(n);
}
static void Enter(double n)
{
Console.WriteLine("You are in Enter Method with DOUBLE parameter");
Console.WriteLine(n);
}
static void New(string st, double s)
{
Console.WriteLine("You are in 'New' Method with 2 parameter: string, double");
Console.WriteLine(st + s);
}
}
}
Hiç yorum yok:
Yorum Gönder