向 VB.NET 中的通用列表的 FindAll 添加参数
很好的问题和有用的答案:
但是任何人都可以帮助将 Jon Skeet 的帮助转化为有效的 .NET 2.0 VB 吗?
我已经通过几个常用的 CSharp 转换器运行了他的答案,但结果无法编译。
Excellent question and useful looking answers at:
Adding a parameter to a FindAll for a Generic List in C#
But can anyone help turn Jon Skeet's assistance into valid .NET 2.0 VB?
I have run his answers through a couple of the usual CSharp converters but the results don't compile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
创建一个从您想要的任何通用列表继承的包装类。然后,重载 FindAll 方法。
编辑添加了运算符枚举以赋予其更多的灵活性。您应该能够从那里扩展。
Create a wrapper class that inherits from whatever Generic List you want. Then, overload the FindAll method.
Edit Added operator Enum to give it a little more flexibility. You should be able to extend from there.
更通用的解决方案是创建一个通用帮助器类,并使用参考值初始化它们。
因为,如果您需要一个整数列表,另一方面需要一个双精度列表,则必须实现两个类,但是,通过这种方法,您只使用一个类。
使用此代码,您可以创建帮助程序,并且可以封装比较逻辑。
A more generic solution is make a generic helper class, and initialize them with the reference value.
Because, if you need a integer list, and in another hand a double list, you must implement two classes, but, with this approach you use only one.
With this code, you create the helper and you could encapsulate the comparison logic.
根据上面的解释和进一步的挖掘......似乎直接的答案是没有直接的 VB 翻译。 VBers 必须走很长的路,至少在 VS2005 中是这样。
最后,我们使用了 Paul Stovell 示例,这是我能找到的最清晰的解决方案。这对我们来说效果很好。
Based on the explanations above and from further digging around ... seems the straight answer is there's no direct VB translation. VBers have to go the long way round, at least in VS2005.
In the end we used the Paul Stovell example which was the clearest solution I could find. This is working fine for us.
我认为你可以做到这一点
这是我的想法,所以我不确定它是否正确。但想法是,您可以使用 AddressOf 调用另一个例程来对列表中的每个项目执行操作。
编辑:代码示例:
I think you can do this
This is off the top of my head, so I'm not sure if it's correct. But the idea is that you can use AddressOf to call another routine to perform actions on each item in the list.
EDIT: Code example: