Method Overloading C# with Example



Method Overloading C# with Example

 	using System;

	namespace CSharpFundamentals
	{
		class MethodOverloading
		{
			private static void Main(string[] args)
			{
				Console.WriteLine("Signature Addition_int_int for 10+20: {0}", Addition(10, 20));
				Console.WriteLine("Signature Addition_int_int_int for 10+20+30: {0}", Addition(10, 20, 30));
				Console.WriteLine("Signature Addition_int_float for 10+20.0f: {0}", Addition(10, 20.3f));
				Console.WriteLine("Signature Addition_float_int for 10.5f+20: {0}", Addition(10.5f, 20));
				Console.WriteLine("Signature Addition_float_float for 10.5f+20.3f: {0}", Addition(10.5f, 20.3f));
			}

			static int Addition(int x, int y)
			{
				return x+y;
			}
			
			static int Addition(int x, int y, int z)
			{
				return x+y+z;
			}
			
			static float Addition(int x, float y)
			{
				return x+y;
			}
			
			static float Addition(float x, int y)
			{
				return x+y;
			}
			
			static float Addition(float x, float y)
			{
				return x+y;
			}
		}
	}
 

0 Comment's

Comment Form