Ishu_15hu

Method Overloading C#

Dec 1st, 2020
381
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. public class sample
  4. {
  5.     //Function Overloading
  6.     public int ADD(int a, int b)
  7.     {
  8.         return (a+b);
  9.     }
  10.    
  11.     public int ADD(int a, int b, int c)
  12.     {
  13.         return (a+b+c);
  14.     }
  15. }
  16. public class Program
  17. {
  18.     public static void Main()
  19.     {
  20.         sample ob = new sample();
  21.        
  22.         Console.WriteLine("a+b = "+ ob.ADD(10,20)); // ADD method with two paremeters
  23.         Console.WriteLine("a+b+c = "+ ob.ADD(10,20,30)); // ADD method with three paremeters                 
  24.     }
  25. }
RAW Paste Data