Method Overloading

  • 하나의 메소드 이름에 여러 개의 구현을 올리는 것
    public class OverLoading  
    {  
      public static int Plus(int a, int b)  
      {  
          return a + b;  
      }  
    	  
      public static double Plus(double a, double b)  
      {  
          return a + b;  
      }  
    	  
      public static void App()  
      {  
          int result1 = Plus(1, 2);  
          double result2 = Plus(3.1, 2.4);  
    	  
          Console.WriteLine($"Result1 : {result1}\nResult2 : {result2}");  
      }  
    }
    

🖍️ 13개 종류의 Overloading을 하고 있는 Console.WriteLine();

public class OverLoading  
{  
	public static int Plus(int a, int b)  
	{  
		WriteLine("Calling int Plus(int,int)...");  
		return a + b;  
	}  
	public static int Plus(int a, int b, int c)  
	{  
		WriteLine("Calling int Plus(int,int,int)...");  
		return a + b + c;  
	}  
	  
	public static double Plus(double a, double b)  
	{  
		WriteLine("Calling double Plus(double, double)...");  
		return a + b;  
	}  
	public static double Plus(int a, double b)  
	{  
		WriteLine("Calling double Plus(int, double)...");  
		return a + b;  
	}  
	  
	public static void App()  
	{  
		WriteLine(Plus(1,2));  
		WriteLine(Plus(1,2,3));  
		WriteLine(Plus(1.0,2.4));  
		WriteLine(Plus(1,2.4));  
	}  
}