zoukankan      html  css  js  c++  java
  • c#函数重载

     

    转:http://blog.csdn.net/jianzaochuanwu/article/details/7587913

    c#函数重载

    分类: c#编程 28人阅读 评论(0) 收藏 举报

    c#方法重载:一个类中可以有一个以上名称相同的方法。但它们的签名不同,也就是括号里面的参数不同。仅方法返回值不同,是不能重载的。也就是方法重载与返回值无关。

    常用的两种重载:

            public static int compute(int x, int y)
            {
                return x + y;
            }
            //方法参数个数不同
            public static int compute(int x, int y, int z)
            {
                return x + y + z;
            }
            //方法参数类型不同
            public static double compute(double x, double y)
            {
                return x + y;
            }

    调用上面的方法:

            static void Main(string[] args)
            {
                Console.WriteLine(compute(3, 2));
                Console.WriteLine(compute(3.1,2.1));
                Console.WriteLine(compute(3, 2, 1));
                Console.ReadKey();
            }

    输出结果:5,5.2,6

  • 相关阅读:
    smbmnt
    smbd
    smbcontrol
    smbclient
    smb.conf
    sleep
    size
    oracle-rman-1
    cURL 学习笔记与总结(5)用 cURL 访问 HTTPS 资源
    Java实现 LeetCode 90 子集 II(二)
  • 原文地址:https://www.cnblogs.com/yran/p/3489973.html
Copyright © 2011-2022 走看看