Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Return 2 values from a function
Message
From
16/10/2008 10:16:33
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
 
To
16/10/2008 08:51:53
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01355203
Message ID:
01355365
Views:
19
>>>>Hi All,
>>>>
>>>>I need to return 2 values from a VB.NET function. One is data type integer and the other string.
>>>>What is the best approach to acomplish that?
>>>>
>>>>Thanks,
>>>>Daniel
>>>
>>>
>>>You may wish to look at your design. A function should perform a single job and return a single value, if you have the need to do more, then I think inherently something is wrong.
>>
>>Do I spot a 'VFP' mindset here :-}.
>>C (and large junks of the windows API) regularly make use of out and ref parameters - even when a structure is used it is often returned as an out parameter. In these cases the main parameter is usually simply a success/fail indicator.
>>What do you think is wrong with this approach?
>>
>>Regards,
>>Viv
>
>
>Viv,
>
>I don't wish to get into a long drawn out argument here. My point is that from a coding standpoint, a method or function should have a single entry point, a single exit point, perform a single function and return a single result. c and the Windows API may not be great examples of programming practice as the current samples for Linq show it being mixed in the UI layer and not in the business or data layer where I think it should belong.
>
>I have no problem with a function returning a boolean value as its main parameter and returning a structure or a single out parameter; but, adding more out parameters or returns leads to code that is difficult to understand, a mess to maintain and is good with a nice Chianti and a marinara sauce.
>
>
>John


I agree. I think MS standards state to return a structure when you need more than a single value as a return parameter. I would use out parameters sparingly.
Very fitting: http://xkcd.com/386/
Previous
Reply
Map
View

Click here to load this message in the networking platform