C#程序使用名称创建ValueType
使用C#7,您可以轻松创建带有名称的ValueType。
注意-添加System.ValueTuple包以运行ValueTuple程序。
让我们看看如何添加它-
去你的项目
右键单击解决方案资源管理器中的项目
选择“管理NuGet软件包”
您将到达NuGet软件包管理器。
现在,单击浏览选项卡并找到“ValueTuple”
最后,添加System.ValueTuple包
示例
using System;
class Program {
static void Main() {
var myTuple = (marks: 95, name: "jack", subject: "maths");
//添加System.ValueTuple包以运行此程序
//使用名称访问
Console.WriteLine("Student Marks: "+myTuple.marks);
Console.WriteLine("Student Name: "+myTuple.name);
Console.WriteLine("Student Subject: "+myTuple.subject);
}
}输出结果
Student Marks: 95 Student Name: Jack Student Subject: Maths
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短