Tech Off Post

Single Post Permalink

View Thread: Ideas for C# 5.0
  • User profile image
    wkempf

    exoteric said:

    I'll start out -

     

    Tuple Syntax 
    a la (precise parenthesization not so important here)

    (1,2,3)

    Tuple Enumeration

    Not a language feature but allow tuple to be enumerated (IEnumerable<T>) for both homogeneous and heterogeneous tuples, meaning these two cases would both be legal

    foreach (var x in (1,2,3))
      Console.WriteLine(x);
    foreach (var x in (1,"WTF",3))
      Console.WriteLine(x);

    Where in the first case the tuple would be IEnumerable<int> and in the second case the tuple would be either IEnumerable<IDynamic> or IEnumerable<Object>.

    I'll agree with tuple syntax, but the (1, 2, 3) stuff isn't the important part. What's much more important is tuple assignment.

     

    int a, b, c;

    (a, b, c) = TupleReturningMethod();