質問

可能な重複:
利回りVB.NET

C#ソースコードの書きる機能を返します。 IEnumerble<>, 利用でき yield return を返す単一の項目が列挙 yield break; に違いない。何VB.NET 文法ることができなくなり、こんなことをしたのだろう。

例から NerdDinner コード:

public IEnumerable<RuleViolation> GetRuleViolations() {

   if (String.IsNullOrEmpty(Title))
       yield return new RuleViolation("Title required","Title");

   if (String.IsNullOrEmpty(Description))
       yield return new RuleViolation("Description required","Description");

   if (String.IsNullOrEmpty(HostedBy))
       yield return new RuleViolation("HostedBy required", "HostedBy");

   if (String.IsNullOrEmpty(Address))
       yield return new RuleViolation("Address required", "Address");

   if (String.IsNullOrEmpty(Country))
       yield return new RuleViolation("Country required", "Country");

   if (String.IsNullOrEmpty(ContactPhone))
       yield return new RuleViolation("Phone# required", "ContactPhone");

   if (!PhoneValidator.IsValidNumber(ContactPhone, Country))
       yield return new RuleViolation("Phone# does not match country", "ContactPhone");

   yield break;
}

この 変換C#るVB.NET ツール この"YieldStatementはサポートされます。

役に立ちましたか?

解決

在していない相当のC#'s利回り返しVB.Net から言語の構文です。

また、近くにMSDN雑誌による法案義の実施の方法について同様のパターンVB.Net 9.0

他のヒント

の新しい 非CTP サポート Yield にVB.NET.

反復子は、視覚の基礎 のための情報。

自分の回答はこちら

をまとめ:
VB.Net ない利回りが、C#具収率で変換するコード状態機械の背後にする。VB.Net's Static キーワードにも保存できる状態、機能、理論的に対応することができるでしょうクラスを実装できる書類のコードとして使用する場合 Static 会員のメソッドになっています。

ない利回り返しVB.NET :( だけのリストを作成して返します。

裏にコンパイラを作成します査を行うクラスです。以降VB.NET なをパターンを作成する必要がある自分の実施IEnumerator(T)

以下の出力です:2,4,8,16,32

VB,

Public Shared Function setofNumbers() As Integer()

    Dim counter As Integer = 0
    Dim results As New List(Of Integer)
    Dim result As Integer = 1
    While counter < 5
        result = result * 2
        results.Add(result)
        counter += 1
    End While
    Return results.ToArray()
End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    For Each i As Integer In setofNumbers()
        MessageBox.Show(i)
    Next
End Sub

クライアントまで、フルのC#

   private void Form1_Load(object sender, EventArgs e)
    {
        foreach (int i in setofNumbers())
        {
            MessageBox.Show(i.ToString());
        }
    }

    public static IEnumerable<int> setofNumbers()
    {
        int counter=0;
        //List<int> results = new List<int>();
        int result=1;
        while (counter < 5)
        {
          result = result * 2;
          counter += 1;
          yield return result;
        }
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top