我想要一个执行此操作的函数:
private static dynamic Zero(Type T)
{
if (T == typeof(Decimal))
{
return Decimal.Zero;
}
else if (T == typeof(Double))
{
return new Double();
}
else if (T == typeof(Int64))
{
return new Int64();
}
...
}
Run Code Online (Sandbox Code Playgroud)
但对于所有类型.我想避免写一个巨大的其他if语句.有没有其他方法可以做到这一点?我正在使用C#4.0.