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();
                con.Open();
                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");
                    adapter.Fill(dataset);
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        attDataType=dr["ATT_DATATYPE"].ToString();
                        attDefValue = dr["ATT_DEFVALUE"].ToString();
                        attDependsOnID = dr["DONID"].ToString();
                        }
                    con.Close();
                }
            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?

Thanks,
LVL 4
o0JoeCool0oAsked:
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.

p_davisCommented:
you can return a tuple
0

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:
http://msdn.microsoft.com/en-us/library/ee332485.aspx

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

and
private void GetAttDataType(out string dt1, out string dt2, out string dt3)
{
//now fill in the values into dt1, dt2 and dt3
}
0
quizwedgeCommented:
As p_davis suggested, using a tuple would work (http://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx)

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 (http://msdn.microsoft.com/en-us/library/tabh47cf(v=vs.110).aspx)
3. Change your function to use pass by reference variables (http://msdn.microsoft.com/en-us/library/0f66670z.aspx) 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.
0
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.