Will a future version of .NET support tuples in C#?

前端 未结 12 1740
别那么骄傲
别那么骄傲 2020-11-28 23:54

.Net 3.5 doesn\'t support tuples. Too bad, But not sure whether the future version of .net will support tuples or not?

12条回答
  •  被撕碎了的回忆
    2020-11-29 00:22

    Here's my set of tuples, they're autogenerated by a Python script, so I've perhaps gone a bit overboard:

    Link to Subversion repository

    You'll need a username/password, they're both guest

    They are based on inheritance, but Tuple will not compare equal to Tuple even if they happen to have the same values for the two first members.

    They also implement GetHashCode and ToString and so forth, and lots of smallish helper methods.

    Example of usage:

    Tuple t1 = new Tuple(10, "a");
    Tuple t2 = new Tuple(10, "a", true);
    if (t1.Equals(t2))
        Console.Out.WriteLine(t1 + " == " + t2);
    else
        Console.Out.WriteLine(t1 + " != " + t2);
    

    Will output:

    10, a != 10, a, True
    

提交回复
热议问题