c# 7.x using a short name for tuple type
c# 7.x using a short name for tuple type
Anyways to use shortcuts for Tuple types, but still preserve the names for each item in the Tuple? (I have created the examples in the code below with my comments.)
/* This way is desired because it keeps the naming for each item in the Tuple,
but incorrect for C# 7.x */
using Employee = (string Name, DateTime StartTime, DateTime LeaveTime,
int Id, double Payment);
/* This way is correct in C# 7.x grammar, but I lost all the names for the items,
and I have to using Item1, Item2 and so on.... */
using Employee = Tuple<string, DateTime, DateTime, int, double>;
public class TestFunc
{
public Employee GetEmployee()
{
Employee value;
value.Name = "Steve";
value.StartTime = new DateTime();
value.EndTime = new DateTime();
return value;
}
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Is the first one valid C# at all?
– john
6 secs ago