public class MyClass1
{
    public MyClass1(){}
    public MyClass1(int i){}
    public static void Main()
    {       
        Type myType = typeof(MyClass1);
        Type[] types = new Type[1];
        types[0] = typeof(int);
        ConstructorInfo constructorInfoObj = myType.GetConstructor(types);
        if (constructorInfoObj != null)
            {
                Console.WriteLine("接受一个整数为参数的构造函数是: "); 
                Console.WriteLine(constructorInfoObj.ToString());
            }   
    }
}请问,代码中,constructorInfoObj.ToString()怎么输出的是个什么东西哦,?.Tostring()不是输出字符串么?
代码如何得到了一个整形参数的构造函数呢?

解决方案 »

  1.   

    constructorInfoObj是个类实例化的对象,对它tostring()》??????
      

  2.   

    constructorInfoObj有属性吗。给属性赋值,再ToString()
      

  3.   

    这是MSDN上的例子http://msdn.microsoft.com/zh-cn/library/h93ya84h.aspx
      

  4.   

    具体怎么回事,查msdn
    构造函数都是.ctr
      

  5.   

    输出的,为什么是这个东西呢:Void.ctor<Int32>
      

  6.   

    ctor是构造函数?哪里讲过啊?没学过呢?
    Void.ctor<Int32>又是什么意思呢?返回值void,一个整形参数,的构造函数,哪里学过这种写法呢
      

  7.   

    ctor 是构造函数,是规定,想想函数的继承的规则或者覆盖的规则是什么?就清楚了
      

  8.   


    public class MyClass1
    {
      public MyClass1(){}
      public MyClass1(int i){}
      public static void Main()
      {   
      Type myType = typeof(MyClass1);//这是获得你的这个类的类别  一般通过反射的时候这里应该是不
                                         //知道类别的  一般通过Assembly对象的方法反射的
      Type[] types = new Type[1];
      types[0] = typeof(int);//这两句话 是准备这个类的构造的参数  明显的 你知道这个类有一个int类
                                //型参数  ConstructorInfo constructorInfoObj = myType.GetConstructor(types);
      //这块是已经得到了这个构造了  但是并没有用这个构造区创建一个对象出来
      //constructorInfoObj的一个方法(大概是Invoke)能搞出一个这个类的对象出来,当然是你得传入int
      //类型的参数
      if (constructorInfoObj != null)
      {
      Console.WriteLine("接受一个整数为参数的构造函数是: ");  
      Console.WriteLine(constructorInfoObj.ToString());//这里仅仅是输出  只是告诉你能反射出来
      //这个构造  正常使用的时候不会这么用
      }   
      }
    }