【发布时间】:2009-09-25 22:07:15
【问题描述】:
伙计们,我正在尝试将某些内容从 C# 转换为 VB.NET,但我在 VB.NET 中找不到与 C# 的 yield 关键字等效的内容。我意识到 'yield' 不是 VB.NET 的可转换关键字,所以有人可以告诉我如何在 VB.NET 中实现此代码。除了实现的 GetEnumerator() 函数外,我将所有这些都转换了。它只是一个实现 CollectionBase 和 IEnumerable 的类(使其值得 LINQ):
[Serializable()]
public partial class Customers : CollectionBase, System.Collections.Generic.IEnumerable<BusinessLayer.Customer>
{
public new System.Collections.Generic.IEnumerator<BusinessLayer.Customer> GetEnumerator()
{
foreach (BusinessLayer.Customer Cust in this.List)
{
yield return Cust;
}
}
public Customers()
{
}
public Customers(DataRowCollection datarows) : this()
{
this.Load(datarows);
}
protected void Load(DataRowCollection dataRows)
{
foreach (DataRow dr in dataRows) {
this.Add(new Customer(dr));
}
}
public Customer this[int index] {
get { return (Customer)base.InnerList[index]; }
set { base.InnerList[index] = value; }
}
public int Add(Customer val)
{
return base.InnerList.Add(val);
}
}
提前感谢您的帮助!
【问题讨论】:
-
如果您告诉他们 Yield 关键字的作用,您可能会从 VB 人员那里获得更多帮助。对于我 35 年运营商的大部分时间,“Yield”意味着一个线程将剩余的 CPU 时间让给调度程序以让任何其他挂起的线程运行。我认为现在 MS 的意思有所不同? (因为有一个简单的、长期存在的 VB 约定)
标签: c# vb.net linq ienumerable