zoukankan      html  css  js  c++  java
  • 什么是重载

    重载条件:

    在同一个类中,同名,返回类型可以不同,参数列表不能相同(参数个数和参数类型),访问修饰符可以不同,最重要的是要同名,具有不同的参数,无论返回值、访问修饰符是否相同,方法名必须相同,参数列表必须不参相同。
    如下类中的重载方法

     class D
        {
            public int test(int n)
            {
                return n;
            }
            internal string test(string str)
            {
                return str;
            }
        }

    下面类中的两个方法参数列表相同,因此重载失败,有编译错误

     class D
        {
            public int test()
            {
                return 12;
            }
            internal string test()
            {
                return "你好!";
            }
        }

    下面类中的两个方法参数列表虽然不同,但仅是因为ref和out关键字而导致的不同,因此也不是重载,有编译错误

    class D
        {
            public int test(ref int n)
            {
                return n;
            }
            internal int test(out int n)
            {
                return n;
            }
        }

  • 相关阅读:
    TcpUDP通讯
    hashlib模块和logging模块
    Windows之系统自带截屏快捷键
    Windows之文件夹中打开PowerShell
    scrapy之管道
    爬虫之通讯协议
    爬虫
    jupyter使用
    MongoDB之$
    MongoDB之修改器
  • 原文地址:https://www.cnblogs.com/liancs/p/3879364.html
Copyright © 2011-2022 走看看