Hello,
Can someone explain to me why the return value is not part of what makes up
the signature of a function?
I would love to be able to overload a function such as:
public overloads function a(x as string, y as string) as DataReader
and
public overloads function a(x as string, y as string) as DataSet
but I find that I cannot do this in vb.net since the signatures are based on
only the passed parameters (at least I couldn't in the net framework 1.0,
and I don't believe it has changed in 1.1)
Do all the .NET languages, (such as c#, etc) all use the same method for
determining the signature for overloading functions?
Thanks!
Jim 4 1646
Hi James, Can someone explain to me why the return value is not part of what makes
up the signature of a function?
That's easy to explain. Let's say you have thwo methods:
public function GetValue() As String
...
end function
public function GetValue() As Integer
....
end function
and in my code, I do the following:
object o = GetValue()
(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function,
sorry. This affects all .NET languages.
Regards,
--
Frank Eller [.NET MVP] www.frankeller.de
..NET Developers Group Munich- www.munichdot.net
The other reason why a return value is NOT considered as a part of the
function signature is because you are not obligated to use the return value
of a function i.e. you can just ignore the return value and use a 'Call
FunctionName' statement instead. In such cases, the compiler simply cannot
resolve the overload.
"Frank Eller [MVP]" <we*******@frankeller.de> wrote in message
news:eu*************@tk2msftngp13.phx.gbl... Hi James,
Can someone explain to me why the return value is not part of what makes up the signature of a function?
That's easy to explain. Let's say you have thwo methods:
public function GetValue() As String ... end function
public function GetValue() As Integer ... end function
and in my code, I do the following:
object o = GetValue()
(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function, sorry. This affects all .NET languages.
Regards,
-- Frank Eller [.NET MVP] www.frankeller.de .NET Developers Group Munich- www.munichdot.net
Hmm...
Wouldn't it be nice though, if one would simply HAVE to specify a default
overload, and the compiler would resolve the overload by the type the return
value is assigned to...
i.e.:
<SomeAttributeSayingThisIsTheDefaultOverLoad()> _
Public Function DoSomething() As String
Public Function DoSomething() As Integer
This way,
Dim i As Integer = DoSomething()
Would cause the Integer overload to be called
Dim s As String = DoSomething()
Would cause the String overload to be called
Dim o As Object = DoSomething()
or
DoSomething()
Would cause the default (in this case String) overload to be called...
Could be something for Framework 2.0 :o)
Danny van Kasteel
"Nice Chap" <Ni******@PlasmaDyne.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... The other reason why a return value is NOT considered as a part of the function signature is because you are not obligated to use the return
value of a function i.e. you can just ignore the return value and use a 'Call FunctionName' statement instead. In such cases, the compiler simply cannot resolve the overload.
"Frank Eller [MVP]" <we*******@frankeller.de> wrote in message news:eu*************@tk2msftngp13.phx.gbl... Hi James,
Can someone explain to me why the return value is not part of what
makes up the signature of a function?
That's easy to explain. Let's say you have thwo methods:
public function GetValue() As String ... end function
public function GetValue() As Integer ... end function
and in my code, I do the following:
object o = GetValue()
(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a
function, sorry. This affects all .NET languages.
Regards,
-- Frank Eller [.NET MVP] www.frankeller.de .NET Developers Group Munich- www.munichdot.net
Thanks for the explanations!
And, Danny, I like your idea... I wonder if there is a 'wish list' place
where we could post that idea for Framework 2.0 or even 1.2 or 1.1.1?
;)
Jim
"Danny van Kasteel" <da***@dlw.nl> wrote in message
news:1063798148.659291@cache2... Hmm...
Wouldn't it be nice though, if one would simply HAVE to specify a default overload, and the compiler would resolve the overload by the type the
return value is assigned to...
i.e.:
<SomeAttributeSayingThisIsTheDefaultOverLoad()> _ Public Function DoSomething() As String Public Function DoSomething() As Integer
This way,
Dim i As Integer = DoSomething()
Would cause the Integer overload to be called
Dim s As String = DoSomething()
Would cause the String overload to be called
Dim o As Object = DoSomething() or DoSomething()
Would cause the default (in this case String) overload to be called...
Could be something for Framework 2.0 :o)
Danny van Kasteel
"Nice Chap" <Ni******@PlasmaDyne.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl... The other reason why a return value is NOT considered as a part of the function signature is because you are not obligated to use the return value of a function i.e. you can just ignore the return value and use a 'Call FunctionName' statement instead. In such cases, the compiler simply
cannot resolve the overload.
"Frank Eller [MVP]" <we*******@frankeller.de> wrote in message news:eu*************@tk2msftngp13.phx.gbl... Hi James,
> Can someone explain to me why the return value is not part of what makes up > the signature of a function?
That's easy to explain. Let's say you have thwo methods:
public function GetValue() As String ... end function
public function GetValue() As Integer ... end function
and in my code, I do the following:
object o = GetValue()
(which is possible), how would you determine which function to use?
The return value is not and cannot be part of the signature of a function, sorry. This affects all .NET languages.
Regards,
-- Frank Eller [.NET MVP] www.frankeller.de .NET Developers Group Munich- www.munichdot.net
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dickster |
last post by:
I notice when moving from VB.NET -> C# that the overloads are different
for
<XMLRoot(....) >
<XMLElement(....) >
but in notice the following seems to compile in C#
|
by: Marcos Stefanakopolus |
last post by:
So this is ok:
class foo {
int myMethod(string, int) { ... }
int myMethod(string, double) { ... }
}
But this is not:
class foo {
|
by: Matt Frame |
last post by:
I have a client that has asked us to get a digital signature certificate and
start digitally signing all files we pass between each other. I have heard
of the subject and know about the certs but...
|
by: Troy |
last post by:
A developer created a Crystal report in .NET.
I added the .RPT file to one of my .NET projects as an existing file.
It immediatly reported several errors in the generated .vb file
where it created...
|
by: Gary Paris |
last post by:
Why would you use an Overloads routine instead of just putting the code in
the default routine?
Private Overloads Sub TextBox1_TextChanged(ByVal sender As System.Object,
ByVal e As...
|
by: jianyi |
last post by:
Hi,
I am working on an xml project, and I am trying to understand
something.
if the author needs to sign one xml file, then his manager will
counter-sign, and a third witness will sign, can...
|
by: André |
last post by:
Hi,
i'm learning working with classes.
In class "classbase1", i defined an overridable function. In the class
"subclass1", i defined the same function with 'Overrides'.
In class "classbase2", i...
|
by: =?Utf-8?B?QU1lcmNlcg==?= |
last post by:
In the class below, I inherit from Generic.Dictionary so I can override
property Item. Item is not overridable, so I used Shadows, and it works as I
want. It works equally well if I replace...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |