简体   繁体   English

从方法中获取多个返回值

[英]Getting multiple return values from method

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.谢谢。

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);
    var result = getInfo("your ID");
    Console.WriteLine($"Status: {result.status}, Info: {result.info}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM