【问题标题】:Alternative to List<Tuple<Grid, TabItem, int, string, int>>... in C#C# 中 List<Tuple<Grid, TabItem, int, string, int>>... 的替代品
【发布时间】:2010-06-21 23:10:13
【问题描述】:

我正在尝试寻找List&lt;Tuple&lt;Grid, TabItem, int, string, int&gt;&gt;... 的替代方案,因为我需要能够修改整数值或字符串值。

我说“替代”是因为我认为不可能修改元组中的任何值。我不想删除它并使用不同的值重新创建它。

【问题讨论】:

    标签: c# list tuples


    【解决方案1】:

    看起来您应该只创建自己的类来保存这些属性,然后您可以强制执行您想要的任何行为。元组主要用于对象的简单捆绑(通常是临时的)。如果你想让一个对象包含所有这些东西,可以编辑某些属性(但不能编辑其他属性?),那么你应该为它编写一个类。

    class BagOfthings
    {
        public Grid Grid {get; private set;}
        public TabItem TabItem {get; private set;}
        public int id {get; private set;}
        public String label {get; set;}
        public int index {get; set;}
    }
    

    显然你应该选择有意义的变量名称:)

    【讨论】:

      【解决方案2】:

      您可能应该列出一个结构列表,在其中命名每个元组元素:

      struct mytype {
          Grid mygrid;
          TabItem myitem;
          int myint;
          // etc
      }
      

      然后使用List&lt;mytype&gt;。当然,您应该将所有这些名称替换为更有意义的名称。

      【讨论】:

        猜你喜欢
        • 2016-05-23
        • 2018-01-25
        • 1970-01-01
        • 2014-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-07
        • 2011-03-05
        • 1970-01-01
        相关资源
        最近更新 更多