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()不是输出字符串么?
代码如何得到了一个整形参数的构造函数呢?
{
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()不是输出字符串么?
代码如何得到了一个整形参数的构造函数呢?
构造函数都是.ctr
Void.ctor<Int32>又是什么意思呢?返回值void,一个整形参数,的构造函数,哪里学过这种写法呢
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());//这里仅仅是输出 只是告诉你能反射出来
//这个构造 正常使用的时候不会这么用
}
}
}