gpt4 book ai didi

c# - 无法从用法中推断出 GetInstance()'。尝试明确指定类型参数

转载 作者:行者123 更新时间:2023-11-30 20:06:29 28 4
gpt4 key购买 nike

<分区>

我创建了一个动态方法来创建不同类型的实例,但不确定为什么它在编译时会出现上述错误,我是否必须再次将返回值转换为指定的类型?

 internal static T GetInstance<T>()
{
dynamic obj = Activator.CreateInstance(typeof(T));
return obj;
}

private Foo f = GetInstance<Foo>();

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com