Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Return 2 values from a function
Message
De
16/10/2008 10:43:17
 
 
À
16/10/2008 08:51:53
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01355203
Message ID:
01355380
Vues:
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,
>

HI,

>I don't wish to get into a long drawn out argument here.

Nor I - let's call it a short discussion :-}

> My point is that from a coding standpoint, a method or function should have a single entry point,

How can it have more? (unless you're counting overloading which isn't really the same thing)

>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.

Not sure of the relevance of Linq here. IAC, although there are samples around that show it being used in the UI, there's no reason that any linkage should exist between them

>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.

Now you've made me hungry. OK: Shall we settle on two return values : the actual return and one out/ref?
(Of course I could still argue a case against that sometimes. Some windows calls would end up sending back a structure of structures
so probably just as confusing as two or three individual structures. Plus you'd have to define a structure for each combination of structures that was being returned....)

Regards,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform