c#组元(Tuple)的使用
组元(Tuple)是C# 4.0引入的一个新特性,可以在.NET Framework 4.0或更高版本中使用。组元使用泛型来简化类的定义,多用于方法的返回值。在函数需要返回多个类型的时候,就不必使用out , ref等关键字了,直接定义一个Tuple类型,使用起来非常方便。
//1 member
Tuple<int> test = new Tuple<int>();
//2 member ( 1< n <8)
Tuple<int, int> test2 = Tuple.Create<int, int>(, );
//8 member, the last member must be tuple type.
Tuple<int, int, int, int, int, int, int, Tuple<int>> test3
= new Tuple<int, int, int, int, int, int, int, Tuple<int>>(, , , , , , , new Tuple<int>()); //output
Console.WriteLine(test.Item1);
Console.WriteLine(test2.Item1 + ", " + test2.Item2);
Console.WriteLine(test3.Item1 + ", " + test3.Item2 + ", " + test3.Item3 + ", " + test3.Item4
+ ", " + test3.Item5 + ", " + test3.Item6 + ", " + test3.Item7 + ", " + test3.Rest.Item1);
更多嵌套定义的例子
//2 member, the second member is the nest type tuple.
Tuple<int, Tuple<int>> test4 = new Tuple<int, Tuple<int>>(, new Tuple<int>());
//10 member,the 8th member is the nest type tuple.
Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>> test5
= new Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>(, , , , , , ,
new Tuple<int, int, int>(, , )); //output
Console.WriteLine(test4.Item1 + ", " + test4.Item2.Item1);
Console.WriteLine(test5.Item1 + ", " + test5.Item2 + ", " + test5.Item3 + ", " + test5.Item4
+ ", " + test5.Item5 + ", " + test5.Item6 + ", " + test5.Item7 + ", "
+ test5.Rest.Item1 + ", " + test5.Rest.Item2 + ", " + test5.Rest.Item3);
c#组元(Tuple)的使用的更多相关文章
- 【转】NumPy-快速处理数据
2.0 简介 标准安装的Python中用列表(list)保存一组值,可以用来当作数组使用,不过由于列表的元素可以是任何对象,因此列表中所保存的是对象的指针(为了保存各种类型的对象,只能牺牲空间).这样 ...
- 语音激活检测(VAD)--前向神经网络方法(Alex)
这是学习时的笔记,包含相关资料链接,有的当时没有细看,记录下来在需要的时候回顾. 有些较混乱的部分,后续会再更新. 欢迎感兴趣的小伙伴一起讨论,跪求大神指点~ VAD(ffnn神经网络)-Alex t ...
- NumPy-高速处理数据
Numpy简单介绍 标准安装的Python中用列表(list)保存一组值,能够用来当作数组使用,只是因为列表的元素能够是不论什么对象,因此列表中所保存的是对象的指针.这样为了保存一个简单的[1,2,3 ...
- C#高级编程第10版 note
泛型接口的抗变和协变 https://www.cnblogs.com/yanfang/p/6635302.html ①泛型接口,如果泛型类型前没有关键字out或者in来标注,则该泛型接口不支持抗变和协 ...
- NumPy-快速处理数据--ndarray对象--多维数组的存取、结构体数组存取、内存对齐、Numpy内存结构
本文摘自<用Python做科学计算>,版权归原作者所有. 上一篇讲到:NumPy-快速处理数据--ndarray对象--数组的创建和存取 接下来接着介绍多维数组的存取.结构体数组存取.内存 ...
- 5、Numpy处理数据
转载自:http://old.sebug.net/paper/books/scipydoc/numpy_intro.html#id9 2 NumPy-快速处理数据 标准安装的Python中用列表(li ...
- 建议10:numpy使用基础
# -*- coding: utf-8 -*- import numpy as np #---------------------------------------- #-- 定义 ndarray ...
- Numpy的那些事儿
2 NumPy-快速处理数据 标准安装的Python中用列表(list)保存一组值,可以用来当作数组使用,不过由于列表的元素可以是任何对象,因此列表中所保存的是对象的指针.这样为了保存一个简单的[1, ...
- python 数组学习
2 NumPy-快速处理数据 标准安装的Python中用列表(list)保存一组值,可以用来当作数组使用,不过由于列表的元素可以是任何对象,因此列表中所保存的是对象的指针.这样为了保存一个简单的[1, ...
随机推荐
- 玩转Docker镜像
镜像是Docker最核心的技术之一,也是应用发布的标准格式.无论你是用docker pull image,或者是在Dockerfile里面写FROM image,从Docker官方Registry下载 ...
- Codeforces 617E XOR and Favorite Number(莫队算法)
题目大概说给一个序列,多次询问区间异或和为k的连续子序列有多少个. 莫队算法,利用异或的性质,通过前缀和求区间和,先处理出序列各个前缀和,然后每次区间转移时维护i以及i-1前缀和为某数的个数并增加或减 ...
- JNDI 配置:JBoss + MySQL
一.JNDI 名词解释 JNDI 是Java 命名和目录接口(Java Naming and Directory Interface,JNDI)的简称.从一开始就一直是 Java 2 平台企业版(JE ...
- java unicode转中文
public static String unicodeToString(String str) { Pattern pattern = Pattern.compile("(\\\\u(\\ ...
- (转)yarn 集群部署,遇到的问题小结
link:http://blog.csdn.net/uniquechao/article/details/26449761 版本信息: hadoop 2.3.0 hive 0.11.0 1. ...
- BZOJ1012[JSOI2008]最大数maxnumber 题解
题目大意: 维护一个数列,有两种操作:1. 查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2.插入操作:将n加上t,其中t是最近一次查询操作的答案(如果还未执行 ...
- C++11 feature: move constructor
There are heaps of good articles out there about C++ features including this move constructor. Howev ...
- Leetcode Reverse Words in a String
Given an input string, reverse the string word by word. For example,Given s = "the sky is blue& ...
- 转载:冷门js技巧
前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前 ...
- 手机web站点和手机app 技术选型的困惑于思考
今年一直在关注移动端技术的发展,自己也用博客园的rss接口玩了半年,关于技术选型的困惑和大家说说 一 趋势 随着手机硬件不断的升级,外加4g牌照的发放,不出2年时间移动端web站点和手机app一定会进 ...