Signatures for Overloads Question

  • Thread starter Thread starter James Radke
  • Start date Start date
J

James Radke

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
 
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,
 
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.
 
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
 
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
 
Back
Top