重载方法名称 [英] overloading method names
本文介绍了重载方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以有两个具有相同名称和参数,但每个方法返回不同数据类型的方法?
即
Hi,
Is it possible to have two methods with the same name and parameters but each return a different datatype?
i.e.
private string executescalar(string param1)
{
...
return string
}
private datetime executescalar(string param1)
{
...
return datetime
}
推荐答案
简单答案不行,这不可能.
Simple answer No, it''s not possible.
在C#中,您不允许要重载返回值,只能在函数的参数上进行此操作.
尝试时编译器会给出错误.
In C# you are not permitted to overload on return value, this can only be done on the parameters of a function.
The compiler will give a error when you try it.
这篇关于重载方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文