zoukankan      html  css  js  c++  java
  • null 与 object

    最近在写代码时定义如下代码形式

     1using System;
     2using System.Collections;
     3public class MyClass
     4{
     5    public static void Main()
     6    {
     7        MyClass my = new MyClass();
     8        my.test(null);
     9        Console.Read();
    10    }

    11    
    12    public void test(string aa)
    13    {
    14        Console.WriteLine("string");
    15    }

    16    
    17    public void test(object aa)
    18    {
    19        Console.WriteLine("object");
    20    }

    21    
    22    //public void test(MyClass1 myClass1)
    23    //{
    24    //    Console.WriteLine("MyClass1");
    25    //}
    26}

    27
    28//public class MyClass1
    29//{}


    本来想输出的结果是object,谁知输出的却是string.
    看来在定义多态和调用null时,一定要注意喽,否则出错了。
    如果把注释去掉,则编译出错。开来只与object有混淆。
    原理,俺不知道,那位知道就指导一下。

  • 相关阅读:
    ubutu16.04编译安装apache
    python格式化字符串
    git服务器搭建
    merge into 导致序列跳号
    Apache 强制SSL访问
    pyhton之解析html的表格
    Two modules in a project cannot share the same content root报错解决方案
    hdoj
    hdoj
    QHUOJ
  • 原文地址:https://www.cnblogs.com/rock_chen/p/199522.html
Copyright © 2011-2022 走看看