Return Multiple Values to a Method Caller

Return multiple values to a method caller

In C# 7 and above, see this answer.

In previous versions, you can use .NET 4.0+'s Tuple:

For Example:

public Tuple<int, int> GetMultipleValue()
{
return Tuple.Create(1,2);
}

Tuples with two values have Item1 and Item2 as properties.

Return multiple values from function

Dart doesn't support multiple return values.

You can return an array,

List foo() {
return [42, "foobar"];
}

or if you want the values be typed use a Tuple class like the package https://pub.dartlang.org/packages/tuple provides.

See also either for a way to return a value or an error.

Return multiple values from a class to method

I think create class is better in this case

   public class MyClass
{
public string Corrente { get; set; }
public string Temperatura { get; set; }
public string NumGiri { get; set; }
}

then

public MyClass Distri(string inArrivo)
{
// your code

MyClass myclass = new MyClass() {
Corrente = corrente,
NumGiri = numGiri,
Temperatura = temperatura
};
return myclass;

}

this is how you can call

Stripper strp = new Stripper();
MyClass myclass = strp.Distri(invia);

// access values as below

textBox7.Text = myclass.NumGiri;

Getting multiple return values from method

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);


Related Topics



Leave a reply



Submit