【C#新特性】不用out ref同时返回多个值-元组Tuple
元组Tuple,它是一种固定成员的泛型集合
下面先看看官方的一个使用例子:
创建一个包含7个元素的Tuple数组
// Create a 7-tuple.
var population = new Tuple<string, int, int, int, int, int, int>( "New York", , , , , , );// Display the first and last elements.
Console.WriteLine("Population of {0} in 2000: {1:N0}",population.Item1, population.Item7);
我们使用Tuple来完成一次简单数据集的传递工作。
将Tuple作为返回值
public List<Tuple<int,string,DateTime>> GetUsers(){
string sql="select ID,Name,CreateTime from Tbl_Users";
using (SqlDataReader r = SqlHelper.ExecuteReader(Connections.AdminDBConString, CommandType.Text, sql))
{
List<Tuple<int,string,DateTime>> list = new List<Tuple<int,string,DateTime>>();
while (r.Read())
{
Tuple<int,string,DateTime> t = new Tuple<int,string,DateTime>(Convert.ToInt32(r[]),r[].ToString(),Convert.ToDatetime(r[]));
list.Add(t);
}
return list;
}
}
//使用也非常方便:
List<Tuple<int,string,datetime>> list=GetUsers();
foreach(Tuple<int,string,datetime> t in list)
{
Console.write(t.Item1);//ID
Console.write(t.Item2);//Name
Console.write(t.Item3);//CreateTime
}
【C#新特性】不用out ref同时返回多个值-元组Tuple的更多相关文章
- Java12新特性 -- 增强G1,自动返回未用堆内存给操作系统
Java 12 中增强了 G1 垃圾收集器关于混合收集集合的处理策略,这节主要介绍在 Java 12 中同时也对 G1垃圾回收器进行了改进,使其能够在空闲时自动将 Java 堆内存返还给操作系统,这也 ...
- H5新特性监听手机的返回键
var hiddenProperty ='hidden' in document ? 'hidden' :'webkitHidden' in document ? 'webkitHidden' : ' ...
- C#6.0,C#7.0新特性
C#6.0新特性 Auto-Property enhancements(自动属性增强) Read-only auto-properties (真正的只读属性) Auto-Property Initia ...
- C# 6.0/7.0 的新特性
转眼C#语言都已经迭代到7.0版本了,很多小伙伴都已经把C# 7.0 的新特性应用到代码中了,想想自己连6.0的新特性都还很少使用,今天特意搜集了一下6.0和7.0的一些新特性,记录一下,方便查阅. ...
- Swift 3到5.1新特性整理
本文转载自:https://hicc.me/whats-new-in-swift-3-to-5-1/,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有. Hipo 2.0 重写从 Swif ...
- 总结一下关于mysql 5.6 新特性
一直断断续续的看一些mysql特性,今天总结一下,以下是列表,网址 http://mariadb.org/ (也是类似的特性), http://mysql.com/ 最近在看关于mysql新特性的一些 ...
- C# 7.0 新特性1: 基于Tuple的“多”返回值方法
本文基于Roslyn项目中的Issue:#347 展开讨论. 1. C# 7.0 新特性1: 基于Tuple的“多”返回值方法 2. C# 7.0 新特性2: 本地方法 3. C# 7.0 新特性3: ...
- C# 7.0 新特性4: 返回引用
本文参考Roslyn项目中的Issue:#118. 1. C# 7.0 新特性1: 基于Tuple的“多”返回值方法 2. C# 7.0 新特性2: 本地方法 3. C# 7.0 新特性3: 模式匹配 ...
- php7函数,声明,返回值等新特性介绍
使用 ... 运算符定义变长参数函数 (PHP 5 >= 5.6.0, PHP 7) 现在可以不依赖 func_get_args(), 使用 ... 运算符 来实现 变长参数函数. functi ...
随机推荐
- Asp.net WebApi下载文件
1,图片 var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(stream ...
- php写文件操作
function writeLog($file, $msg, $mode='a+') { $fp = fopen($file, $mode); if(flock($fp, LOCK_EX)) { fw ...
- Compile cpp File Manually without IDE under Mingw Environment
环境准备. 安装mingw并设置好系统PATH. mingw.windows下的GUN编程环境. 系统变量的作用--可运行文件的搜索路径. 这样在cmd直接输入g++就能调用到D:\Program F ...
- excel做回归分析的应用【风控数据分析】
方法1 统计逻辑:统计一个loginname的所有去重的通讯录数C,统计这个Loginname对应的每个设备对应的通讯录c1,c2,c3…cn; X=(c1/c+c2/c+c3/c+….cn/ ...
- 软件设计模式之模板方法模式(JAVA)
什么是模板方法模式? 定义一个操作中算法的骨架,而将这些步骤延迟到子类中,模板方法使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定步骤. 好抽象的概念啊,文绉绉的东西就是不讨人喜欢,下面我 ...
- UITextField禁用掉编辑之后...
某些UITextField只为了摆数据,还有响应点击,为了避免频繁出现键盘,所以把UITextField的人机交互(userInteractionEnabled)给关闭了 此时,给UITextFiel ...
- 【Jupyter notebook】access remotly
http://jupyter-notebook.readthedocs.io/en/latest/public_server.html
- Fedora 安装oracle11g 之最简洁方式
最新的Fedora 24已经释出. 赶紧尝试安装oracle11g一把.很简单,很方便. 此处以最最简洁方式来安装一把! 环境: windows xp + virtualbox ,安装 fedora ...
- Android 安全提示 笔记
http://developer.android.com/training/articles/security-tips.html1.数据存储内部存储internal storage存储的数据,只能由 ...
- redis队列操作
PHP版: <?php /** * Redis * 配置 $redis_host,$redis_port * 队列操作 * @author win 7 */ class RQueue{ priv ...