卡住通用类型约束
假设我有两种通用方法:
int GetValue<T>() where T: unmanaged
{}
int GetAnotherValue<T>()
{}
我需要将呼叫转发给这样的一种方法:
void Init<T>()
{
int i;
//here is my problem
if( T is unmanaged)
i = GetValue<T>();
else
i = GetAnotherValue<T>();
}
我不知道如何根据通用类型T派遣调用。 有人可以帮我吗? 谢谢。
Say i have two generic methods:
int GetValue<T>() where T: unmanaged
{}
int GetAnotherValue<T>()
{}
I need to forward a call to one of those methods like this:
void Init<T>()
{
int i;
//here is my problem
if( T is unmanaged)
i = GetValue<T>();
else
i = GetAnotherValue<T>();
}
I do not figure how to dispatch the call based on the generic type T.
Can someone help me?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论