关于PowerShell调用Linq的一组实验
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
PS C:\> $a = 0..2
PS C:\> $b = 3..5
PS C:\> $a.tostring()
System.Object[]
PS C:\> $c = [Linq.Enumerable]::Zip($a, $b, [Func[Object, Object, Object]]{$args[0]+$args[1]})
PS C:\> $c
3
5
7
PS C:\> $c[0]
3
5
7
PS C:\> $c.tostring()
System.Linq.Enumerable+<ZipIterator>d__61`3[System.Object,System.Object,System.Object]
PS C:\> $d = $c | % { $_ }
PS C:\> $d[0]
3
PS C:\> $d.tostring()
System.Object[]
PS C:\> $c = [Linq.Enumerable]::Zip($a, $b, [Func[Object, Object, Object]]{ @{ i=$args[0]; j=$args[1] } })
PS C:\> $c
Name Value
---- -----
j 3
i 0
j 4
i 1
j 5
i 2
PS C:\> $c[0]
Name Value
---- -----
j 3
i 0
j 4
i 1
j 5
i 2
PS C:\> $c.i
0
1
2
PS C:\> $c.tostring()
System.Linq.Enumerable+<ZipIterator>d__61`3[System.Object,System.Object,System.Object]
PS C:\> $d = $c | % { $_ }
PS C:\> $d
Name Value
---- -----
j 3
i 0
j 4
i 1
j 5
i 2
PS C:\> $d[0]
Name Value
---- -----
j 3
i 0
PS C:\> $d[0].i
0
PS C:\> $d.tostring()
System.Object[]
PS C:\> $c = [Linq.Enumerable]::Zip($a, $b, [Func[Object, Object, Object]]{ ($args[0], $args[1]) })
PS C:\> $c
0
3
1
4
2
5
PS C:\> $c.tostring()
System.Linq.Enumerable+<ZipIterator>d__61`3[System.Object,System.Object,System.Object]
PS C:\> $c[0]
0
3
1
4
2
5
PS C:\> $d = $c | % { $_ }
PS C:\> $d
0
3
1
4
2
5
PS C:\> $d[0]
0
PS C:\> $d[1]
3
PS C:\> $d.tostring()
System.Object[]
PS C:\> $d = [Linq.Enumerable]::ToArray($c)
PS C:\> $d[0]
0
3
PS C:\> $d[0][0]
0
PS C:\> $d.tostring()
System.Object[]
PS C:\> $c = [Linq.Enumerable]::Zip($a, $b, [Func[Object, Object, int[]]]{($args[0], $args[1])})
PS C:\> $c[0]
0
3
1
4
2
5
PS C:\> $c.tostring()
System.Linq.Enumerable+<ZipIterator>d__61`3[System.Object,System.Object,System.Int32[]]
PS C:\> $d = $c | % { $_ }
PS C:\> $d[0]
0
PS C:\> $d[1]
3
PS C:\> $d.tostring()
System.Object[]
PS C:\> $d = [Linq.Enumerable]::ToArray($c)
PS C:\> $d[0]
0
3
PS C:\> $d[0][0]
0
PS C:\> $d.tostring()
System.Int32[][]
PS C:\> $c = [Linq.Enumerable]::Zip($a, $b, [Func[Object, Object, Object]]{$l = [Collections.Generic.List[int]]::new(); $l.Add($args[0])
; $l.Add($args[1]); $l}) PS C:\> $c[0]
0
3
1
4
2
5
PS C:\> $d = $c | % { $_ }
PS C:\> $d[0]
0
PS C:\> $d[1]
3
PS C:\> $d.tostring()
System.Object[]
PS C:\> $d = [Linq.Enumerable]::ToArray($c)
PS C:\> $d[0]
0
3
PS C:\> $d[0][1]
3
调用Linq返回的那个类型我不太清楚,但应该是一个实现了IEnumerable的类,不能直接当作数组使用,但可以用For-Object(%)进行迭代。因此可见,当Zip内部匿名函数返回的是非可迭代类型时,可以使用For-Object(%)命令将Zip返回的类转化为由可迭代类型的数组,而当返回的是可迭代类型,使用For-Object(%)命令会将Zip返回的类平摊为一个一维数组,这样就不能达到我们的要求,需要使用[Linq.Enumerable]::ToArray 方法才能将其转化为“二维数组”。
关于PowerShell调用Linq的一组实验的更多相关文章
- PowerShell调用jira rest api实现jira统计自动化
通过调用JIRA Rest web api实现统计自动化,首先进行登录模拟: $content = @{username='用户名';password='密码'} $JSON=$content|con ...
- JS里面匿名函数的调用 & 变量作用域的实验
参考 http://www.educity.cn/wenda/54753.html 已实验验证结果正确. 1.下列哪些正确?(B.C) A.function(){ alert("Here!& ...
- Powershell调用静态方法
Powershell将信息存储在对象中,每个对象都会有一个具体的类型,简单的文本会以System.String类型存储,日期会以System.DateTime类型存储.任何.NET对象都可以通过Get ...
- 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法
比如Json.NET的JObject明明实现了IEnumerable<T>,具体来说是IEnumerable<KeyValuePair<string, JToken>&g ...
- 系统功能调用Windows操作系统原理实验
一.实验目的 1.熟悉操作系统的系统功能调用. 2.掌握用C语言实现系统功能调用的方法和步骤. 3.掌握利用10H号功能调用(BIOS的显示I/O功能调用)来实现对屏幕的操作与控制. 二.实验内容 1 ...
- 【手记】走近科学之为什么JObject不能调用LINQ扩展方法
Json.NET的JObject明明实现了IEnumerable<T>,具体来说是IEnumerable<KeyValuePair<string, JToken>> ...
- 一句powershell调用mimikatz抓密码
mimikatz神器大家都知道吧,可以抓取系统内的明文密码,但是平时我们测试的时候需要把mimikatz的几个文件上传到目标系统上面,然后再手工执行几个命令才能搞定,今天无意访问一个大神的博客,发现其 ...
- C++ 构造函数 隐式转换 深度探索,由‘类对象的赋值操作是否有可能调用到构造函数’该实验现象引发
Test1 /** Ques: 类对象的赋值操作是否有可能调用到构造函数 ? **/ class mystring { char str[100]; public: mystring() //myst ...
- 【Azure 环境】用 PowerShell 调用 AAD Token, 以及调用Azure REST API(如资源组列表)
问题描述 PowerShell 脚本调用Azure REST API, 但是所有的API都需要进行权限验证.要在请求的Header部分带上Authorization参数,并用来对List Resour ...
随机推荐
- [计网笔记] 传输层---UDP
- mybatis的嵌套查询与嵌套结果查询的不同
原文:https://blog.csdn.net/qq_39706071/article/details/85156840 实体类: 嵌套查询mapper方法:嵌套查询的弊端:即嵌套查询的N+1问题尽 ...
- cb30a_c++_STL_算法_查找算法_(3)search_find_end
cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...
- 一文带你了解Redis持久化完整版本
本文讲解知识点 持久化的简介 RDB AOF RDB与AOF的区别 持久化应用场景 对于持久化这个功能点,其实很简单没有那么复杂 演示环境 centos7.0 redis4.0 redis存放目录:/ ...
- opencv c++访问某一区域
int main(){ cv::Mat m1(,, CV_8UC1); for(int i=;i<m1.rows;++i) for(int j=;j<m1.cols;++j) m1.at& ...
- Spring Cloud面试题万字解析(2020面试必备)
1.什么是 Spring Cloud? Spring cloud 流应用程序启动器是 于 Spring Boot 的 Spring 集成应用程序,提供与外部系统的集成.Spring cloud Tas ...
- skywalking学习ppt
和传统应用监控的区别,Dapper论文 监控图
- SSH网上商城三
现在我们要实现下面的需求: 当用户点击左侧二级菜单选项的时候,在右侧要显示对应的该二级菜单项下面存在哪些商品,例如点击潮流女装,要在右侧分页显示该潮流女装下对应哪些商品 1.要分页显示 首先要获得该二 ...
- laravel Excel 导入
<?php namespace App\Modules\Live\Http\Controllers; use Illuminate\Http\Request; use Maatwebsite\E ...
- mock api测试demo
前言 本测试demo基于Spring框架测试,这几个月也是刚刚接触Spring的项目.如果不对的地方请多谅解. 正文 1.创建测试类,添加注解 @RunWith(SpringRunner.class) ...