【发布时间】:2014-02-13 17:52:12
【问题描述】:
考虑一下 C++/CLI 中的这个简单代码
template <typename T>
T sum (T x, T y)
{
return x + y;
}
int main(array<System::String ^> ^args)
{
int a=4, b=6;
double x=2.3, y=5.2;
Console::WriteLine("Sum of two ints = {0}", sum(a, b));
Console::WriteLine("Sum of two doubles = {0}", sum(x, y));
return 0;
}
输出:
Sum of two ints = 10
Sum of two doubles = 7.5
如何在 C# 中使用泛型做到这一点?
【问题讨论】:
标签: c# templates generics c++-cli