Click to See Complete Forum and Search --> : A little interesting comment on VB.Net


Boumxyz2
September 2nd, 2004, 02:24 PM
Okay I Haven't been using VB.Net for a while... Just since april.

and I thought this language was really object oriented... well
I got some news. It's better than vb6 on this part but not good
enough to my taste.

Return value of a function isn't part of the Function Name so in
a OO point of view

this isn't possible


Public Function A(ByVal str as string) As int

End Function
Public Function A(ByVal str as string) As long

End Function


Which in a way makes VB .NET OO capability somewhat limited...

Anyway just wanted to let you know for those that didn'T know..

If you have any workaround let me know.

DSJ
September 2nd, 2004, 04:16 PM
I'm not exactly sure what your point is. Are you wanting to define both of those methods at the same time for a given class? If so, that's not possible because the compiler wouldn't know which to call (the have the same signature). Also, why would you want a given method to return two different types?

Craig Gemmill
September 2nd, 2004, 07:56 PM
Yeah, I'm not sure this would be the best idea. At some point you have to rely on the compiler to guess which function you really wanted to use. The only way the compiler would know which function to run would be based on a comparison between the return type and the variable type that is waiting for the return. What if there was no variable waiting for a return, or if you used a type that is a base type for both functions.

I know that’s confusing; here is an example:


Private Function DoSomething() as ListBox
'blah...
End Function

Private Function DoSomething() as ListView
'blah...
End Function

'Now, what would the compiler do in these situations:

DoSomething()

'or

Dim o as Object
o = DoSomething()

'In either case, the compiler would have to guess which function you wanted to execute.

Boumxyz2
September 2nd, 2004, 11:24 PM
in ADA, the return type is part of the signature. Anyway I'll work around that

DSJ
September 3rd, 2004, 09:29 AM
Just return an object.