Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
}        
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading