您如何将对象投射到元组? [英] How do you cast an object to a Tuple?

查看:44
本文介绍了您如何将对象投射到元组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建我的元组并将其添加到组合框中:

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

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

现在,我希望将该项目投射为元组,但这不起作用:

Now I wish to cast the item as a Tuple, but this does not work:

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

我该怎么做?

推荐答案

投射时不要忘记():

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

这篇关于您如何将对象投射到元组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆