CodeIterationStatement Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Egy utasítást for vagy egy utasításblokkon keresztüli hurkot jelöl, amely egy tesztkifejezést használ a ciklus folytatásának feltételeként.
public ref class CodeIterationStatement : System::CodeDom::CodeStatement
public class CodeIterationStatement : System.CodeDom.CodeStatement
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeIterationStatement : System.CodeDom.CodeStatement
type CodeIterationStatement = class
inherit CodeStatement
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeIterationStatement = class
inherit CodeStatement
Public Class CodeIterationStatement
Inherits CodeStatement
- Öröklődés
- Attribútumok
Példák
Ez a példa azt mutatja be, hogy egy CodeIterationStatement ciklust egy adott ciklus ábrázolására for használ.
// Declares and initializes an integer variable named testInt.
CodeVariableDeclarationStatement testInt = new CodeVariableDeclarationStatement(typeof(int), "testInt", new CodePrimitiveExpression(0) );
// Creates a for loop that sets testInt to 0 and continues incrementing testInt by 1 each loop until testInt is not less than 10.
CodeIterationStatement forLoop = new CodeIterationStatement(
// initStatement parameter for pre-loop initialization.
new CodeAssignStatement( new CodeVariableReferenceExpression("testInt"), new CodePrimitiveExpression(1) ),
// testExpression parameter to test for continuation condition.
new CodeBinaryOperatorExpression( new CodeVariableReferenceExpression("testInt"),
CodeBinaryOperatorType.LessThan, new CodePrimitiveExpression(10) ),
// incrementStatement parameter indicates statement to execute after each iteration.
new CodeAssignStatement( new CodeVariableReferenceExpression("testInt"), new CodeBinaryOperatorExpression(
new CodeVariableReferenceExpression("testInt"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression(1) )),
// statements parameter contains the statements to execute during each interation of the loop.
// Each loop iteration the value of the integer is output using the Console.WriteLine method.
new CodeStatement[] { new CodeExpressionStatement( new CodeMethodInvokeExpression( new CodeMethodReferenceExpression(
new CodeTypeReferenceExpression("Console"), "WriteLine" ), new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("testInt"), "ToString" ) ) ) } );
// A C# code generator produces the following source code for the preceeding example code:
// int testInt = 0;
// for (testInt = 1; (testInt < 10); testInt = (testInt + 1)) {
// Console.WriteLine(testInt.ToString());
' Declares and initializes an integer variable named testInt.
Dim testInt As New CodeVariableDeclarationStatement(GetType(Integer), "testInt", New CodePrimitiveExpression(0))
' Creates a for loop that sets testInt to 0 and continues incrementing testInt by 1 each loop until testInt is not less than 10.
' initStatement parameter for pre-loop initialization.
' testExpression parameter indicates the epxression to test for continuation condition.
' incrementStatement parameter indicates statement to execute after each iteration.
' statements parameter contains the statements to execute during each interation of the loop.
' Each loop iteration the value of the integer is output using the Console.WriteLine method.
Dim forLoop As New CodeIterationStatement( _
New CodeAssignStatement(New CodeVariableReferenceExpression("testInt"), New CodePrimitiveExpression(1)), _
New CodeBinaryOperatorExpression(New CodeVariableReferenceExpression("testInt"), _
CodeBinaryOperatorType.LessThan, New CodePrimitiveExpression(10)), _
New CodeAssignStatement(New CodeVariableReferenceExpression("testInt"), _
New CodeBinaryOperatorExpression(New CodeVariableReferenceExpression("testInt"), _
CodeBinaryOperatorType.Add, New CodePrimitiveExpression(1))), _
New CodeStatement() {New CodeExpressionStatement( _
New CodeMethodInvokeExpression(New CodeMethodReferenceExpression(New CodeTypeReferenceExpression("Console"), "WriteLine"), _
New CodeMethodInvokeExpression(New CodeVariableReferenceExpression("testInt"), "ToString")))})
' A Visual Basic code generator produces the following source code for the preceeding example code:
' Dim testInt As Integer = 0
' testInt = 1
' Do While (testInt < 10)
' Console.WriteLine(testInt.ToString)
' testInt = (testInt + 1)
Megjegyzések
Egy CodeIterationStatement ciklust vagy for hurkot while jelölhet.
A InitStatement tulajdonság az első ciklus iterációja előtt végrehajtandó utasítást adja meg. A TestExpression tulajdonság megadja a ciklusfolytatási kifejezést, amelynek az egyes ciklus-iterációk végén kell kiértékelnie true , hogy egy másik iteráció kezdődjön. A IncrementStatement tulajdonság az egyes ciklus iterációk végén végrehajtandó utasítást adja meg. A Statements tulajdonság a cikluson belül végrehajtandó utasítások gyűjteményét adja meg.
Konstruktorok
| Name | Description |
|---|---|
| CodeIterationStatement() |
Inicializálja a CodeIterationStatement osztály új példányát. |
| CodeIterationStatement(CodeStatement, CodeExpression, CodeStatement, CodeStatement[]) |
Inicializálja az CodeIterationStatement osztály új példányát a megadott paraméterekkel. |
Tulajdonságok
| Name | Description |
|---|---|
| EndDirectives |
Lekéri a CodeDirectiveCollection végfelhasználói irányelveket tartalmazó objektumot. (Öröklődés forrása CodeStatement) |
| IncrementStatement |
Lekéri vagy beállítja az egyes ciklusok után meghívott utasítást. |
| InitStatement |
Lekéri vagy beállítja a hurok inicializálási utasítását. |
| LinePragma |
Lekéri vagy beállítja azt a sort, amelyen a kódutasítás történik. (Öröklődés forrása CodeStatement) |
| StartDirectives |
Lekéri a CodeDirectiveCollection kezdő irányelveket tartalmazó objektumot. (Öröklődés forrása CodeStatement) |
| Statements |
Lekéri a cikluson belül végrehajtandó utasítások gyűjteményét. |
| TestExpression |
Lekéri vagy beállítja a ciklust folytató feltételként tesztelni kívánt kifejezést. |
| UserData |
Lekéri az aktuális objektum felhasználó által definiálható adatait. (Öröklődés forrása CodeObject) |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal. (Öröklődés forrása Object) |
| GetHashCode() |
Ez az alapértelmezett kivonatoló függvény. (Öröklődés forrása Object) |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |