vb.net - Why can't I have two methods with the same parameters but different returns? -


.net allows...

public function one(a integer) string... public function one(b string) string... 

it figures out 1 call looking @ type of parameters, like...

dim string = one(5) 

ok, why can't this...

public function one(a integer) string... public function one(b integer) integer... 

the same amount of information available compiler...

dim integer = one(5) ' should know call second version 

the specific problem i'm trying solve return values in dictionary(of integer, myclass) is visible com interop. return .values ienumerable. lose type inside own code, pita. if have 2 methods have 1 returns ienumerable , returns list(of myclass) , api same in both places. have 2 different method names, kind of defeats purpose.

i'm open solution fixes underlying problem... there single type can return avoids directcast in own code, while still being visible com interop?

short answer : because return type isn't included in method's signature

the relevant part of spec

the following not part of member's signature, , hence cannot overloaded on:

  • modifiers type member (for example, shared or private).
  • modifiers parameter (for example, byval or byref).
  • the names of parameters.
  • the return type of method or element type of property.

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -