Guest User

Guest User

  • Tech Writer
  • 48
  • 11.9k

Passing a ValueTuple return type as an argument.

Oct 15 2019 12:34 PM
I am interested in retrieving a tuple of multiple values from a class method and then passing that result directly to another class method. See example code to see what I intend (it does not compile):
 
Edit: I realize that I could use "(double, double) myVar" as the parameter and then use myVar.Item1, and myVar.Item2, but I would prefer to be able to use the terms that I define and not something so generic. 
  1. class ClassA  
  2. {  
  3.     public static (doubledouble) GetTuple()  
  4.     {  
  5.         return (12.5, 13.5);  
  6.     }  
  7. }  
  8.   
  9. public partial class MainWindow : Window  
  10. {  
  11.     public MainWindow()  
  12.     {  
  13.         InitializeComponent();  
  14.         ClassB.ShowTuple(ClassA.GetTuple());  
  15.     }  
  16. }  
  17.   
  18. public static class ClassB  
  19. {  
  20.     public static void ShowTuple((double myVar1, double myVar2))  
  21.     {  
  22.         Console.WriteLine(myVar1);  
  23.         Console.WriteLine(myVar2);  
  24.     }  
  25. }  
The problem appears to be in ClassB with the parameter passed to ShowTuple. I tried it without the extra parenthesis, as a Tuple, ValueTuple, etc., but nothing seems to work.
 
Does anyone know what I am missing?
Thanks! 
 
 

Answers (2)