面朝大海,春暖华开

focus on scientific computue, 3dgis, spatial database
专注于科学计算、GIS空间分析

 

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");

 

posted on 2017-08-20 23:24  风过 无痕  阅读(430)  评论(0编辑  收藏  举报

导航

向日葵支付宝收钱码