结合元组的列表 [英] binding to a list of tuples

查看:160
本文介绍了结合元组的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的元组配对两个数据的列表...我想列表绑定到数据网格。对于显示器,它工作正常......但如果我尝试和修改一个条目,它说:一个双向或者OneWayToSource结合不能在只读属性项目1工作......想必元组是在.NET 4.0中不可改变的。有没有绑定到两双数据,而无需创建一个可变的元组类我自己的一个简单的方法?

I have a list of tuples pairing two pieces of data... I'd like to bind the list to a data grid. For display, it works fine... but if I try and modify an entry, it says "A TwoWay or OneWayToSource binding cannot work on the read-only property 'Item1'"... presumably Tuples are immutable in .NET 4.0. Is there an easy way to bind to pairs of data without creating a mutable tuple class of my own?

推荐答案

是,元组是不可改变的。匿名类型也是不可改变的。你应该用你自己的泛型类型:

Yes, tuples are immutable. Anonymous types are also immutable. You should use your own generic type:

public class Pair<T, U> 
{
     public Pair() {
     }

     public Pair(T first, U second) {
       this.First = first;
       this.Second = second;
     }

     public T First { get; set; }
     public U Second { get; set; }
};

这篇关于结合元组的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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