【发布时间】:2011-05-23 05:18:40
【问题描述】:
我有以下方法:
void s<t>(int a, t b)
{
...
..
.
}
void s<int>(int a, int b)
{
...
..
.
}
void s<long>(int a, long b)
{
...
..
.
}
当我想将它用作s<long>(10,10) 时,我会在工具提示中看到这些覆盖。
s<long>(int a,int b); 和 s<long>(int a,long b);。但是,我想我必须只看到s<long>(int a,long b);。
怎么了?我有 visual studio 2008 sp1。
谢谢
更新:我在 Visual Studio 2010 中测试过,结果是一样的。 更新:似乎是关于 c# 而不是 Visual Studio。
【问题讨论】:
-
ints 可以自动提升为longs,所以这是正确的行为。 -
这些不是覆盖 - 它们是重载。而且你没有声明这样的泛型方法......
标签: c# generics methods overloading