How to return three values from a function in c#?

Hi Experts,

I am writing a function which should return three string values and my code looks like this.
private String GetAttDataType(string dt)
             string attDa = null;
             string attDe = null;
           string attDep = null;
            string ConString = "User Id=sys;Password=sys;Data Source=T";
            using (OracleConnection con = new OracleConnection(ConString))
                OracleDataAdapter adapter = new OracleDataAdapter();
                OracleCommand command = new OracleCommand("SELECT ATT_DATATYPE,ATT_DEFVALUE, DONID FROM T.ATTRIBUTES WHERE ATTRIBUTE_NUMBER=" + dt, con);
                    adapter.SelectCommand = command;
                    DataSet dataset = new DataSet("ATTDATATYPE1");
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                        attDefValue = dr["ATT_DEFVALUE"].ToString();
                        attDependsOnID = dr["DONID"].ToString();
            return attDa;

Open in new window

Is there any work around for this? Or Can you please share some ideas on how to resolve it?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can return a tuple

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
A function can only return one value - but it is up to you what type of object that is, it could be a class.

An alternative is to use the parameter list (either as ref or as out keywords), see:

string dt1, dt2, dt3
GetAttDataType(dt1, dt2, dt3)

private void GetAttDataType(out string dt1, out string dt2, out string dt3)
//now fill in the values into dt1, dt2 and dt3
As p_davis suggested, using a tuple would work (

If for some reason a tuple doesn't work, you could also
1. Return an array
2. Return a string separated by some delimiter such as |and use String.Split (
3. Change your function to use pass by reference variables ( You would then pass in three additional strings to your function and set those. The code that calls this function would have the values.

Tuple is best, but providing a few other options just in case. Order preference would probably be tuple, array, delimited string, and, only if you have to, reference variables.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.