gpt4 book ai didi

.net - Linq 和对象的包装器

转载 作者:行者123 更新时间:2023-12-04 04:53:39 25 4
gpt4 key购买 nike

我有一个类MyObj有一个 Width属性(property)。
我需要将该属性从 MyObj 删除到 MyObjWrapper这将包装 MyObj。
我像这样使用它:

Dim _MyObjWrapper As MyObjWrapper = New MyObjWrapper(_myObj)
Dim theWidth as Integer = _MyObjWrapper.Width

选择我使用的 MyObj 的特定宽度
Dim q = From mo In myContainer.GetMyObjs() 
Where mo.Width > 50
Select mo.Width Distinct

现在,如果 Width不再属于 MyObj,我想用 moWrapper.Width 代替 mo.Width :
Dim q = From mo In myContainer.GetMyObjs() 
Where New MyObjWrapper(mo).Width > 50
Select New MyObjWrapper(mo).Width Distinct

有没有办法不使用 2 次包装器的构造函数 MyObjWrapper(mo)?

最佳答案

我的 VS 安装现在表现得很疯狂,所以我无法测试这个,但试试这样的:

Dim q = From mo In myContainer.GetMyObjs() 
Let someObj = New MyObjWrapper(mo)
Where someObj.Width > 50
Select someObj.Width.Distinct

关于.net - Linq 和对象的包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17066012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com