Anonymous type and tuple

Just a little update to this answer since C# 7 is out in the wild. Tuples have super powers now and can sometimes replace anonymous types and classes. Take for example this method that accepts and returns tuples with named properties.

To help illustrate what is possible, the Whatever function transforms the input shape and values.

void Main()
{
    var tupleInput = (Neat: 123, Cool: true);
    var tupleOutput = Whatever(tupleInput);
    Debug.Assert(tupleOutput.Something == 133);
    Debug.Assert(tupleOutput.Another == "True");
}

(int Something, string Another) Whatever((int Neat, bool Cool) data)
{
    return (Something: data.Neat + 10, Another: data.Cool.ToString());
}

That’s cool.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)