LINQ 选择语法 VB.NET

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45467568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 20:19:05  来源:igfitidea点击:

LINQ Select Syntax VB.NET

vb.netlinq

提问by Belgin Fish

I have a list of TuplesI am trying to run a Selectand Wherequery on to return a list of Objectsfrom the Tuple.Item5parameter. In my where clause I am looking to match Tuple.Item4to a local variable.

我有一个Tuples我正在尝试运行SelectWhere查询的列表,以ObjectsTuple.Item5参数返回一个列表。在我的 where 子句中,我希望匹配Tuple.Item4一个局部变量。

I'm not sure what the VB.NET syntax is for the Select portion, I only know the c# syntax.

我不确定 Select 部分的 VB.NET 语法是什么,我只知道 c# 语法。

Essentially I am trying to select Tuple.Item5from my list of tuples where Tuple.Item4 = sCurID. I'm unsure as to what should go in the Select section although in c# I believe it would be Select(t => t.Item5)

本质上,我试图Tuple.Item5从我的元组列表中选择Tuple.Item4 = sCurID。我不确定 Select 部分应该包含什么,尽管在 c# 中我相信它会是Select(t => t.Item5)

This is what I have:

这就是我所拥有的:

listObj = listTuples.Select( Unsure What Goes Here ).Where(Function(w) w.Item4 = sCurID)

回答by NetMage

Once you apply the Selectin C# or VB, you have reduced the Tuple to the Item5value and can't access Item4. Do the Selectlast:

一旦你Select在 C# 或 VB 中应用了,你已经将元组减少到Item5值并且无法访问Item4. 做Select最后:

Dim listObj = listTuples.Where(Function(t) t.Item4 = sCurId).Select(Function(t) t.Item5)

回答by XardasLord

listObj = listTuples.Select(Function(t) t.Item5).Where(Function(w) w.Item4 = sCurID).ToList()