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

前端 未结 12 1741
别那么骄傲
别那么骄傲 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:10

    #region tuples
    
        public class Tuple
        {
            public Tuple(T first)
            {
                First = first;
            }
    
            public T First { get; set; }
        }
    
        public class Tuple : Tuple
        {
            public Tuple(T first, T2 second)
                : base(first)
            {
                Second = second;
            }
    
            public T2 Second { get; set; }
        }
    
        public class Tuple : Tuple
        {
            public Tuple(T first, T2 second, T3 third)
                : base(first, second)
            {
                Third = third;
            }
    
            public T3 Third { get; set; }
        }
    
        public class Tuple : Tuple
        {
            public Tuple(T first, T2 second, T3 third, T4 fourth)
                : base(first, second, third)
            {
                Fourth = fourth;
            }
    
            public T4 Fourth { get; set; }
        }
    
        #endregion
    

    And to make declarations prettier:

    public static class Tuple
    {
        //Allows Tuple.New(1, "2") instead of new Tuple(1, "2")
        public static Tuple New(T1 t1, T2 t2)
        {
            return new Tuple(t1, t2);
        }
        //etc...
    }
    

提交回复
热议问题