【问题标题】:List of Tuple trouble元组麻烦列表
【发布时间】:2012-02-24 13:45:51
【问题描述】:

编辑:已解决,很抱歉,这是由于打字错误。


这段代码。

List<Tuple<Int16, Int16>> a = new List<Tuple<Int16, Int16>>();
Tuple<UInt16, UInt16> b = Tuple.Create<UInt16, UInt16>(4, 2);
a.Add(b);

a.Add(b) 产生以下错误

The best overloaded method match for
'System.Collections.Generic.List<System.Tuple<short,short>>
.Add(System.Tuple<short,short>)'
has some invalid arguments.

总之

List<Tuple<short,short>>.Add(Tuple<short,short>)
has invalid arguments

我看不出这是怎么回事。

【问题讨论】:

  • @dtb:这就是答案。要么你回答问题,要么我们关闭它,因为这必须是重复的:-)

标签: c# list collections tuples abstraction


【解决方案1】:

Tuple&lt;Int16, Int16&gt;Tuple&lt;UInt16, UInt16&gt; 是两种不同类型的元组。

【讨论】:

    【解决方案2】:

    您正在尝试将 UInt16 对添加到 Int16 对的列表中。这行不通。

    您可以将Int16 对添加到Int16 对列表中:

    List<Tuple<Int16, Int16>> a = new List<Tuple<Int16, Int16>>();
    Tuple<Int16, Int16> b = Tuple.Create<Int16, Int16>(4, 2);
    a.Add(b);
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        【解决方案4】:

        它准确地告诉您问题和解决方案。试试短而不是无符号短

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-22
          • 2020-07-09
          • 2018-05-25
          • 1970-01-01
          相关资源
          最近更新 更多