By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,556 Members | 1,663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,556 IT Pros & Developers. It's quick & easy.

Signatures for Overloads Question

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
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

Nov 20 '05 #3

P: n/a
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


Nov 20 '05 #4

P: n/a
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



Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.