c# - 为什么这个 LINQ 查询不起作用?

标签 c# winforms linq

我试图帮助其他人并写下这个查询:

var foundTab = (from tab in tabControl1.TabPages
                where tab.Name == "tabName"
                select tab).First();

他们报告说他们收到了这个错误:

Could not find an implementation of the query pattern for source type System.Windows.Forms.TabControl.TabPageCollection'. 'Where' not found. Consider explicitly specifying the type of the range variable 'tab'.

我检查了 MSDN,TabPageCollection 实现了 IListICollectionIEnumerable。那么,这是怎么回事?该错误是什么意思,还有其他方法可以查询选项卡控件的 TabPages 属性吗?

最佳答案

试试这个:

var tab = (from System.Windows.Forms.TabPage tab in tabControl1.TabPages
           where tab.Name == "tabName"
           select tab).First();

此代码指定范围变量的类型。

关于c# - 为什么这个 LINQ 查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1523457/

相关文章:

c# - 为什么我的 C# 应用程序不能在不同的机器上执行?

c# - 我应该为来自 TextBox 控件的序列化数据指定哪种编码

c# - LINQ Where() : are these two LINQ statements the same?

c# - 如何从静态方法访问控件?

c# - Xamarin 工作簿 : Use of namespaces

c# - 无法创建类型为 'xxx' 的常量值。在此上下文中仅支持原始类型或枚举类型

c# - TagHelper 指定有效属性

c# - 将 datetimepicker 的值传递给代码隐藏 (c#)

c# - 通用类型作为变量

c# - 直接访问 TableLayoutPanel 单元格