你传的什么高级类型,竟然会报错Type type =result.GetType(); Type type = typeof( T );如果根据不同数据类型作不同处理,也可以这样 if ( result is int ) { MessageBox.Show( "Int" ); } else if ( result is Form ) { MessageBox.Show( "Form" ); } else { MessageBox.Show( "Other" ); }
static Type TestMethod<T>(T result) { Type type = result.GetType(); return type; }
typeof 只能用于。,不知道怎么表达,就是类型名称,如int Form TextBox,不能用于这些类的实例。 GetType是实例方法。
Type t = typeof(T);
public TOutput Method<TInput,TOutput>(TInput T) {}
if(result is 类名) 或者result.GetType().ToString()就知道是什么类型了
Type type = typeof( T );如果根据不同数据类型作不同处理,也可以这样 if ( result is int )
{
MessageBox.Show( "Int" );
}
else if ( result is Form )
{
MessageBox.Show( "Form" );
}
else
{
MessageBox.Show( "Other" );
}
{
Type type = result.GetType();
return type;
}
GetType是实例方法。
Type t = typeof(T);
{}
或者result.GetType().ToString()就知道是什么类型了