473,890 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return multiple values

can a method return multiple values?

pseudo code

public string method1()
{
//db pull

select col1, col2, from tb1
s1 = col1;
s2 = col2;

return s1, s2?
}

string1 = method1[s1]
string2 = method1[s2]
Nov 15 '05 #1
4 27240
Normally in such a situation the best is to return an object that is
constructed within your method and that will expose, as property, data you
have initialized within your method.

José
"Aaron" <ku*****@yahoo. com> wrote in message
news:eF******** ******@TK2MSFTN GP12.phx.gbl...
can a method return multiple values?

pseudo code

public string method1()
{
//db pull

select col1, col2, from tb1
s1 = col1;
s2 = col2;

return s1, s2?
}

string1 = method1[s1]
string2 = method1[s2]

Nov 15 '05 #2
could you give me an example?

im new to c#

thanks
"José Joye" <jo*******@KILL THESPAMSbluewin .ch> wrote in message
news:e8******** *****@TK2MSFTNG P11.phx.gbl...
Normally in such a situation the best is to return an object that is
constructed within your method and that will expose, as property, data you
have initialized within your method.

José
"Aaron" <ku*****@yahoo. com> wrote in message
news:eF******** ******@TK2MSFTN GP12.phx.gbl...
can a method return multiple values?

pseudo code

public string method1()
{
//db pull

select col1, col2, from tb1
s1 = col1;
s2 = col2;

return s1, s2?
}

string1 = method1[s1]
string2 = method1[s2]


Nov 15 '05 #3
Aaron <ku*****@yahoo. com> wrote:
can a method return multiple values?


Not directly, no. Possibilities are:

o Return an array of values instead (this looks fairly appropriate in
your example)
o Return a composite object which is the logical representation of all
those values (this makes sense in terms of a method only doing one
thing)
o Use ref/out parameters (rarely a good idea in terms of clean
separation etc, but can avoid you making extra classes just for the
sake of returning them)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
struct thingy
{
public column s1;
public column s2;
}

public thingy method1()
{
select col1, col2, from tb1
thingy t = new thingy();
t.s1 = col1;
t.s2 = col2;
return t;
}

Another way would be to use ref or out

column s1;
column s2;

public void method1(out value1, out value2)
{
select col1, col2, from tb1
value1 = col1;
value2 = col2;
}

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
For a laugh, try web browsing with Opera's User Mode and Nostalgia enabled
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
5057
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
4
10701
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
5
1778
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to return a single value. No big deal. But I want to call a Function from another Sub and the function finds and returns an entire db record. Using ASP.NET (VB!), how can this be done and how can I differentiate between the fields/columns? For...
16
17419
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
18
2463
by: skishorev | last post by:
Hi, Here I am taking two functions. void f(int,int) and another one is float f(int,int). Is it possible to overload with return values. Thx, kishore
8
5216
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return more than one value, for example three int-s, I would have to change my "logic" and pass the references to my
1
2762
by: v4u2chat | last post by:
Do I need to extend any of classes from AXIS to return multiple values? I'm exposing the following method as web service through AXIS to return multiple values. public ContactAddress testService() { ContactAddress cAddr = new ContactAddress(); cAddr.setAddresses1("AAAAAAAAAAAAA"); cAddr.setAddresses2("BBBBBBBBBBBBB"); cAddr.setAddresses3("CCCCCCCCCCCCC");
80
41370
by: xicloid | last post by:
I'm making a function that checks the input integer and returns the value if it is a prime number. If the integer is not a prime number, then the function should return nothing. Problem is, I don't know how to do that. Isn't there anything like "return null"in C?
2
3686
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne Traditionally, one has always thought that Functions can only return a single value, and for the most part that was true. Ever since Access 95, we gained the new functionality, through VBA, to have Functions return an entire Structure of values. A User...
4
7151
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input parameters and returns the two return values. My C# programmer here says that webservice methods can only return 1 value per method. Is that right? Though I haven't ever created a webservice, I would have thought that a method could return a whole lot...
0
9826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10829
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7171
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4682
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.