- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
是否可以使用 LINQ 转换包含坐标元组 (x, y) 的平面 double 组,即[x0,y0, ..., xN, yN] 到长度为一半的数组,其中包含包装在 Point
类中的相同坐标,即 [p0, ..., pN]?
最好是 .NET 3.5,但也对 4.0 感兴趣。
最佳答案
您可以使用 .Batch
来自 Jon Skeet 的 morelinq :
IEnumerable<Point> points = coordinates.Batch(2,pair => new Point(pair.ElementAt(0), pair.ElementAt(1)));
老实说,最简单的解决方案可能是使用一种方法(这里使用 int
s):
public IEnumerable<Point> GetPoints(int[] coordinates)
{
for (int i = 0; i < coordinates.Length; i += 2)
{
yield return new Point(coordinates[i], coordinates[i + 1]);
}
}
关于c# - LINQ 将数组 [x0,y0, ..., xN, yN] 转换为可枚举的 [p0, ..., pN],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6592604/
这是我正在编写的程序的基本代码,用于练习在 C 中使用文件。我正在尝试检测输出文件是否已经存在,如果它确实存在,我想询问用户是否要覆盖它或不。这就是我首先使用 fopen(outfilename,"r
这个问题已经有答案了: Variable might not have been initialized error (12 个回答) 已关闭 3 年前。 我已经初始化了变量 yn,但它一直说我没有初
我经常使用 Ruby gem clean 命令来保持本地 gem 存储库的良好状态。 但是,由于依赖性问题,很多时候该命令会返回如下提示: XXXXX-1.0.6 depends on [YYYYYY
运行follow命令向yarn提交作业,但不期望分配任务管理器的数量。集群有足够的资源 /data/clusterserver/flink-1.7.2/bin/flink run -m yarn-cl
是否可以使用 LINQ 转换包含坐标元组 (x, y) 的平面 double 组,即[x0,y0, ..., xN, yN] 到长度为一半的数组,其中包含包装在 Point 类中的相同坐标,即 [p0
我是一名优秀的程序员,十分优秀!