c# 7 vs2017 tuple
var unnamed = (42, "The meaning of life");
var anonymous = (16, "a perfect square");
var named = (Answer: 42, Message: "The meaning of life");
var differentNamed = (SecretConstant: 42, Label: "The meaning of life");
named = unnamed;
(int Answer, string Message) named2 = (42, "The meaning of life");
(int Answer, string Message) differentNamed2 = (42, "The meaning of life");
下面错误:
var named3 = (int Answer, string Message)(42, "The meaning of life");
var differentNamed3 = (int Answer, string Message)(42, "The meaning of life");
既然(int Answer, string Message)是类型名,(42, "The meaning of life")是变量值,为什么类型名不能放在变量值前面呢?何况类型一致。
或者Tuple<int Answer, string Message> named4 =(42, "The meaning of life");
var named5 = Tuple<int Answer, string Message>(42, "The meaning of life");