Search code examples
c#methodsreturn-type

How to return more than one integer values with a return statement in a user-defined method with integer return type in C#?


namespace MyApp
{
    class Program
    {
         static int check(int id, int age)
        {
           return id,age; //  adding age gives error 
        }
        public static void Main(string[] args)
        {
            check(3064,24);
        }
    }
}

Solution

  • By using tuples:

    static (int, int) check(int id, int age)
    {
        return (id,age);
    }
    

    You can also name the values in your tuple:

    static (int id, int age) check(int id, int age)
    {
        return (id,age);
    }