Provides a simple example of function overloading : Function Overloading : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Function Overloading »

 

Provides a simple example of function overloading









    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

//
// Overload.cs -- Provides a simple example of function overloading
//
//                Compile this program with the following command line:
//                    C:>csc Overload.cs
//
namespace nsOverload
{
    using System;
    
    public class clsMainOverload
    {
        static public void Main ()
        {
            int iVal = 16;
            long lVal = 24;
            Console.WriteLine ("The square of {0} is {1}\r\n",
                               iVal, Square(iVal));
            Console.WriteLine ("The square of {0} is {1}",
                               lVal, Square(lVal));
        }
        static int Square (int var)
        {
            Console.WriteLine ("int Square (int var) method called");
            return (var * var);
        }
        static long Square (long var)
        {
            Console.WriteLine ("long Square (long var) method called");
            return (var * var);
        }
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Function Overloading