0

Not so long ago I moved from Java to C# and I'm still learning and today I bumped into this in some code.

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?

Victor Wilson
  • 1,720
  • 1
  • 11
  • 22
Mr.Gomer
  • 501
  • 5
  • 14
  • 5
    A [Tuple](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples) that is wrapped in a [Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1?view=net-6.0). – Igor Aug 17 '22 at 19:56
  • 3
    Does this answer your question? [c# anonymous type declaration with parentheses](https://stackoverflow.com/questions/65647070/c-sharp-anonymous-type-declaration-with-parentheses) – gunr2171 Aug 17 '22 at 19:57
  • u can just return a tuple like that in c# not as a dictionary or HashSet – Mr.Gomer Aug 17 '22 at 19:57

1 Answers1

3

This returns a tuple of (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
mathis1337
  • 1,426
  • 8
  • 13