【发布时间】:2016-11-07 17:52:05
【问题描述】:
在 C# 中:是否可以使用泛型参数类的类型作为方法的返回类型或定义成员?
C++ 示例:
class AgrumentClass
{
typedef int type;
public:
static type GetSomething() { return 0; }
};
template< class T >
class GenericClass
{
typedef typename T::type type;
public:
static type GetSomething() { return T::GetSomething(); }
};
int main()
{
int value = GenericClass<AgrumentClass>::GetSomething();
return value;
}
【问题讨论】:
-
我投票结束这个问题,因为它不是代码转换工具!
-
是的,你可以学习 c# 泛型,并且几乎可以在任何地方使用它们 msdn.microsoft.com/en-us/library/512aeb7t.aspx
-
@mybirthname 他不是要代码转换工具。他在问 C# 中是否有并行功能,并包含一个 C++ 示例来展示他所指的概念。
-
@BrianWarshaw 好吧,如果我给你写一个汇编代码并问这在 c# 中是否可行,是不是代码转换?