0
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);
        }
    }
}
Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • check this https://stackoverflow.com/questions/748062/return-multiple-values-to-a-method-caller – M Rizwan Apr 25 '22 at 08:05
  • Please make use of the `{ }` button above the text box for your next question that contains a code block. Also we do prefer some words other than code to be in a question; tell us what youre trying to do, what youre expecting to get and what you're actually getting including the full exact text of any error messages – Caius Jard Apr 25 '22 at 08:39

1 Answers1

1

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);
}        
Palle Due
  • 5,929
  • 4
  • 17
  • 32
  • How to remove brackets beside this program's output and get it like this 3064,24 thanks – Shazma Batool Apr 25 '22 at 08:27
  • *You can also name the values in your tuple* - you can do that on the receiving end too, doesn't have to be on the method: `(int id, int age) x = ...`, and you can deconstruct by omitting the name of the tuple `(int id, int age) = check...` or `var (id, age) = check...`. See https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/deconstruct – Caius Jard Apr 25 '22 at 08:41
  • @CaiusJard: Yes, I was going to extend my answer with that, but it was already closed, so I didn't bother. – Palle Due Apr 25 '22 at 10:32
  • @ShazmaBatool: You can't do that. The syntax is like that. If you just mean adressing the items of the tuple, see the comment made by CaiusJard. – Palle Due Apr 25 '22 at 10:35