简体   繁体   English

这个方法返回什么? (C#)

[英]What does this Method return? (C#)

Not so long ago I moved from Java to C# and I'm still learning and today I bumped into this in some code.不久前,我从 Java 转到 C# 并且我还在学习,今天我在一些代码中遇到了这个问题。

public async Task<(decimal Price, string NativeCurrency)> GetCurrentStockPrice(string ticker)

I'm wondering just based on the method signature what exactly does this method return?我想知道仅基于方法签名该方法究竟返回什么? Does it return two values?它是否返回两个值?

This returns a tuple of (decimal Price, string NativeCurrency)这将返回一个元组(decimal Price, string NativeCurrency)

So you would call所以你会打电话

var currentStockPrice = await GetCurrentStockPrice("USD") //or whatever the ticket string needs to be instead of "USD"

and

currentStockPrice.Item1 is decimal Price
currentStockPrice.Item2 is string NativeCurrency

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

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