使用LINQ二维阵列,请选择未找到 [英] Using Linq with 2D array, Select not found

查看:685
本文介绍了使用LINQ二维阵列,请选择未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用LINQ查询二维数组,但我得到一个错误:

I want to use Linq to query a 2D array but I get an error:

找不到源类型的查询模式的实现SimpleGame.ILandscape [ 的]。
      选择未找到。是否缺少为System.Core.dll或using指令System.Linq的?

Could not find an implementation of the query pattern for source type 'SimpleGame.ILandscape[,]'. 'Select' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'?

code为以下内容:

Code is following:

var doors = from landscape in this.map select landscape;

我检查,我包括参考 System.Core程序,并使用 System.Linq的

任何人都可以提供一些可能的原因是什么?

Could anyone give some possible causes?

推荐答案

为了使用您的多维数组使用LINQ,您只需将其转换为的IEnumerable< T> 。这是很简单的,这里有两个例子选项查询

In order to use your multidimensional array with LINQ, you simply need to convert it to IEnumerable<T>. It's simple enough, here are two example options for querying

int[,] array = { { 1, 2 }, { 3, 4 } };

var query = from int item in array
            where item % 2 == 0
            select item;

var query2 = from item in array.Cast<int>()
                where item % 2 == 0
                select item;

每个语法将二维数组转换成的IEnumerable&LT; T&GT; (因为你说 INT项在一个从条款或 array.Cast&LT; INT&gt;在其他())。然后,可以过滤,选择,或执行你想使用LINQ方法无论投影。

Each syntax will convert the 2D array into an IEnumerable<T> (because you say int item in one from clause or array.Cast<int>() in the other). You can then filter, select, or perform whatever projection you wish using LINQ methods.

这篇关于使用LINQ二维阵列,请选择未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆