Return multiple values from the function


We can return multiple values from the function by using out parameters.
   
    The out parameters are used to return values in the same variables, that you pass an an argument of a method.out parameters are very useful when your method needs to return more than one values.

    Example:

    using System;
    class SomeName
    {
        public static void Main(String [] args)
        {
           int a,b=0;
           b=ParamTest(out a);
           Console.WriteLine("a = {0}", a);
           Console.WriteLine("b = {0}", b);
         }
        public static int ParamTest(out int a)
        {
            a=200;
            return 10;
        }
    }

   output :  a=200 b=10;

No comments:

Post a Comment