如果在团队开发中,A组员 编写了 A.cs文件,由于范型方法会自动识别, 运行结果是
“This is Generic Method”//A.cs文件
namespace TestGeneric
{
partial class Program
{
static void Main(string[] args)
{
ShowDifference(1);
Console.ReadLine();
} static void ShowDifference<T>(T t)
{
Console.WriteLine("This is Generic Method");
} }
}如果另外一个组员 B 写了B.cs代码 ,就会改变A.cs的运行结果
//B.cs
namespace TestGeneric
{
partial class Program
{
static void ShowDifference(int Num)
{
Console.WriteLine("This is NON-Generic Method");
}
}
}这样的话 A.cs 的运行结果就是 “This is NON-Generic Method”;个人觉得范型方法重载微软设计的不周全,在这个地方 编译器至少 应该发出一个warning .
“This is Generic Method”//A.cs文件
namespace TestGeneric
{
partial class Program
{
static void Main(string[] args)
{
ShowDifference(1);
Console.ReadLine();
} static void ShowDifference<T>(T t)
{
Console.WriteLine("This is Generic Method");
} }
}如果另外一个组员 B 写了B.cs代码 ,就会改变A.cs的运行结果
//B.cs
namespace TestGeneric
{
partial class Program
{
static void ShowDifference(int Num)
{
Console.WriteLine("This is NON-Generic Method");
}
}
}这样的话 A.cs 的运行结果就是 “This is NON-Generic Method”;个人觉得范型方法重载微软设计的不周全,在这个地方 编译器至少 应该发出一个warning .
解决方案 »
- 关于directshow提取视频帧图像的问题?
- ADO.NET的菜鸟问题!!急!!
- 请教一个简间的问题:MDI中关掉一个子窗体,然后用菜单再打开怎么弄呀????
- cmd.ExecuteNonQuery();调试时该语句出错,求救~~~~
- c#.net做安装包的问题
- ==================c# treeview中,如何知道我点的+是哪个node?===================
- 删除excel表中数据的问题
- 求助,vs2010 同时打开两个C#创建的窗口项目就会崩溃
- 删除tablecontrol中的tabpage
- 有没有方法将 一批word文件转成html
- 讨论c#的内存情况,大家共同努力啊
- 如何获得SqlDataReader对象里有多少条数据?
不过这不应该算是错误,这是函数重载,main里执行的那个函数,你传入一个int,肯定优先掉用b.cs 的方法
如果使用接口
public interface IMethod
{
void Method1<T>(T t);
}
所有的类都派生自这个接口,那么,如果不实现这个泛型的方法肯定会报错。
static void Main(string[] args)
{
ShowDifference(1); //非范型函数也就是B.cs里的
ShowDifference<int>(1);范型函数也就是A.cs里的 Console.ReadLine();
}