Csharp/C Sharp/Language Basics/Function Overloading — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:39, 26 мая 2010

Provides a simple example of function overloading

<source lang="csharp"> /* 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);
       }
   }

}


      </source>