Method Overloading


/ Published in: C#
Save to your folder(s)

To accomplish Method Overloading, a developer can define two or more methods with the same name. Each method will take a different set of parameters. The parameter combination or signature, is what the compiler uses to determine which method to use.


Copy this code and paste it in your HTML
  1. using System;
  2. namespace MethodOverloading
  3. {
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. MethodOverloadPlay(10, 3);
  9. Console.WriteLine("+++++");
  10. MethodOverloadPlay(5, 5, 6);
  11. Console.WriteLine("+++++");
  12. MethodOverloadPlay("SP");
  13. Console.ReadLine();
  14. }
  15.  
  16. static void MethodOverloadPlay(int number1, int number2)
  17. {
  18. int result = number1 + number2;
  19. Console.WriteLine(result);
  20. }
  21.  
  22. static void MethodOverloadPlay(int number1, int number2, int number3)
  23. {
  24. int result = number1 + number2 + number3;
  25. Console.WriteLine(result);
  26. }
  27.  
  28. static void MethodOverloadPlay(string string1)
  29. {
  30. Console.WriteLine("Breaking Benjamin & Sick Puppies Rock!");
  31. }
  32. }
  33. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.