Console.WriteLine(new my()); 你输出的是个对象  好像!

解决方案 »

  1.   

    我想输出对象进,会调用该对象的ToString()方法吧?
      

  2.   

    你输出了一个my对象实例而你的my是基于CollectionBase的。和toString没有关系。。要想测试你的代码应该是:my ToString=new my();
    Console.WriteLine(ToString.toString());
      

  3.   

    因该是调用类的构造方法,不会调用这个ToString()吧!
    要是把return hello写构造函数里,应该可以输出吧!
      

  4.   

    经测试是hello
    lz逗我们玩呢。
      

  5.   

    public class  my:CollectionBase 

       public override string  ToString() 
       { 
          return "hello"; 
       } 
    } Console.WriteLine(new my()); -----------------------------------------------Console.WriteLine((new my()).ToString()); 
      

  6.   


    Console.WriteLine(new my()); 
    输出对象本身时,应该会调用该对象的ToString方法,但现在好像调用的是CollectionBase(父类)的ToString方法,因为结果为:COLLECTION.,还望高手指点!!
      

  7.   

    经过测试确实输出的是hello啊,楼主拿我们寻开心吧.
      

  8.   

    //项目:多列combobox
    ...
    ...//定义my集合类,用以存放多列Combobox中的一行
    public class  my:CollectionBase  
    {  
      ....
      public my():base()
      { this.clear();  }  public int add(string v)//添加进集合
      {
         return this.innerList.add(v);
      }  public override string ToString()
      {
          return this.innerList[0].toString();
      }
      .......
    }  //sub
    my a1=new my();
    a1.add("001");
    a1.add("zhangsan");
    a1.add("20");my a2=new my();
    a2.add("002");
    a2.add("wangwu");
    a2.add("22");combobox1.items.add(a1);
    combobox1.items.add(a2);
    ......
    ///sub end怎么在Combobox1中选择第一项时,combobox1.text为001
    怎么在Combobox1中选择第二项时,combobox1.text为002
    现在,无论选择那项,combobox1.text都是:"collection"
      

  9.   

    combobox1.items.add(a1); a1是当object添加进去了吧?你没ToString()?
      

  10.   

    懂你什么意思,重写object的ToString来代替ToString现在,无论选择那项,combobox1.text都是:"collection"  这句是怎么理解?COMBOBOX里面已经是001 002了没?
      

  11.   

    我测试了下,你这份代码是没问题的, comboBox里面是001 002,ToString也起了正确的作用,现在你问题在哪请明确指出
      

  12.   

    Console.WriteLine((new my()).ToString()); 
    是"hello"
      

  13.   

    我测试了下,你这份代码是没问题的, comboBox里面是001 002,ToString也起了正确的作用,现在你问题在哪请明确指出
    我现在出现在不是001  002 而是"collection"
      

  14.   

    Console.WriteLine((new my()).ToString());
      

  15.   

    collection是哪出来?你该查查这个,你所给的代码里面没见到~
      

  16.   

    public override string ToString() 
      { 
          return this.innerList[0].toString(); 
      } 
    ===========
    innerList 具体定义??
      

  17.   

    collection是哪出来?你该查查这个,你所给的代码里面没见到~ 
    ====================================================
    我想可能是my类继承自collectionbase 中的问题,但是不知道怎么来查找"collection"的来源!!! 
     
      

  18.   

    public class  my:CollectionBase 

       public override string  ToString() 
       { 
          return "hello"; 
       } 

    ---------------------
    CollectionBase s = new my();
    Console.WriteLine(s);
      

  19.   


       public new  override string  ToString()
       {
          return "hello";
       } 
      

  20.   

    public new  override string  ToString() 
       { 
          return "hello"; 
       } 
      

  21.   

    Are you exaggerating yourself? if yes, then close it please