Home > database >  Getting multiple return values from method
Getting multiple return values from method

Time:03-04

I'm trying to use a library and the below code is its documentation about the method that I'll have to call

public extern static (int status, string info) getInfo(string ID); 

My question is, how can I get the return value form this method ? I can call the method and pass in the parameters but I don't know how to get the return values since they are multiple.

Thanks.

CodePudding user response:

The return value is essentially a Tuple. You can access the data by specifying the names of each value (status, errors, etc.) or accessing them by the returned name.

public extern static (int status, string info) getInfo(string ID); 

var (status, info) = getInfo("id");

or

var retVals = getInfo("id");
var status = retVals.status;
var info = retVals.info;

and use the variables like normal.

DisplayStatus(status);

LogInfo(info);

CodePudding user response:

    var result = getInfo("your ID");
    Console.WriteLine($"Status: {result.status}, Info: {result.info}");
  •  Tags:  
  • c#
  • Related