在C#中:是否可以使用泛型參數類的類型作爲方法的返回類型或定義成員?類似於C++模板中的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;
}
我投票結束這個問題作爲題外話,因爲它不是代碼轉換工具! – mybirthname
是的,這是可能的,你可以學習C#泛型,你可以在任何地方使用它們https://msdn.microsoft.com/en-us/library/512aeb7t.aspx –
@mybirthname他沒有要求代碼轉換工具。他問C#中是否有並行功能,並且包含一個C++示例來展示他所指的概念。 –