【发布时间】:2014-10-03 00:08:50
【问题描述】:
我尝试通过他们的键从列表中获取值。我将列表从一种形式发送到另一种形式。这是 Windows 窗体应用程序请参阅我的代码:
/* First form! */
var list1 = new List<KeyValuePair<string, int>>();
list1.Add(new KeyValuePair<string, int>("Cat", 1));
form2 f3 = new form2(connection , list1);
/* Form2 */
private IList<KeyValuePair<string, int>> _theList;
public editAccount(string connection, List<KeyValuePair<string, int>> arr)
{
InitializeComponent();
_theList = arr;
label1.Text = _theList["Cat"];
}
我认为这显然是我尝试做的,所以任何帮助都很棒!
已解决:感谢 stackoverflow 用户 Sriram Sakthivel!解决方案:
/* First form*/
Dictionary<string, string> openWith = new Dictionary<string, string>();
openWith.Add("cat", "test");
editAccount f3 = new editAccount(connection, openWith);
/* Form 2 */
private Dictionary<string, string> _theList;
public editAccount(string connection, Dictionary<string, string> arr)
{
InitializeComponent();
_theList = arr;
label1.Text = _theList["cat"];
}
【问题讨论】: