How to return multiple values from function?


To return multiple values from function

Declaring an out method is useful when you want a method to return multiple values.

It can also return one or more objects to a calling method as out parameters


class Ex
{
static void AssignVal(out int i)
{
i = 99;
}
static void Main()
{
int tmp;
AssignVal(out tmp);
}
}


Now tmp value is 99.

Multiple values

class Ex
{
static double AssignVal(out int i)
{
i = 99;
return i + 1;
}
static void Main()
{
int tmp;
double Result=AssignVal(out tmp);
}
}


Now Assignval return multiple values for i =99 and result will be 100


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: