How do you overlay an object on a Tuple?

I create my Tuple and add it to the combo box:

comboBox1.Items.Add(new Tuple<string, string>(service, method));

Now I want to pass the element as a tuple, but this does not work:

Tuple<string, string> selectedTuple = 
                   Tuple<string, string>(comboBox1.SelectedItem);

How can i do this?

+5
source share
2 answers

Do not forget ()when pressed:

Tuple<string, string> selectedTuple = 
                  (Tuple<string, string>)comboBox1.SelectedItem;
+12
source

Your syntax is incorrect. It should be:

Tuple<string, string> selectedTuple = (Tuple<string, string>)comboBox1.SelectedItem;

As an alternative:

var selectedTuple = (Tuple<string, string>)comboBox1.SelectedItem;
+3
source

All Articles