閱讀英文版本

分享方式:


FieldDirection 列舉

定義

定義用於指示參數方向和引數宣告的識別項。

C#
public enum FieldDirection
C#
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FieldDirection
繼承
FieldDirection
屬性

欄位

名稱 Description
In 0

輸入的欄位。

Out 1

輸出的欄位。

Ref 2

欄位參考。

範例

下列範例示範如何使用 FieldDirection 來指出方法宣告中方法參數的欄位方向類型。

C#
// Declares a method.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "TestMethod";

// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression("System.String", "stringParam");
param1.Direction = FieldDirection.Ref;
method1.Parameters.Add(param1);

// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression("System.Int32", "intParam");
param2.Direction = FieldDirection.Out;
method1.Parameters.Add(param2);

// A C# code generator produces the following source code for the preceeding example code:

//        private void TestMethod(ref string stringParam, out int intParam) {
//        }

備註

FieldDirection 允許依傳址方式,或使用傳入或傳出參數將自變數傳遞至函式。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱