C#函数重载

using System;namespace PolymorphismApplication {class Printdata {void print(int i) {Console.WriteLine(Printing int: {0}, i );

编程学习网为您整理以下代码实例,主要实现:C#函数重载,希望可以帮到各位朋友。

using System;

namespace polymorphismApplication {

   class Printdata {

      voID print(int i) {
         Console.Writeline("Printing int: {0}", i );
      }

      voID print(double f) {
         Console.Writeline("Printing float: {0}" , f);
      }

      voID print(string s) {
         Console.Writeline("Printing string: {0}", s);
      }

      static voID Main(string[] args) {
         Printdata p = new Printdata();

         // Call print to print integer
         p.print(5);

         // Call print to print float
         p.print(500.263);

         // Call print to print string
         p.print("Hello C++");
         Console.ReadKey();
      }
   }
}

本文标题为:C#函数重载

上一篇: C#动态多态性
下一篇: C#调用方法示例2