FieldDirection 枚举

定义

定义用于指示参数的方向和参数声明的标识符。

public enum FieldDirection
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public enum FieldDirection
继承
FieldDirection
属性

字段

名称 说明
In 0

传入字段。

Out 1

输出字段。

Ref 2

传址方式字段。

示例

以下示例演示如何使用 FieldDirection 指示方法声明中方法参数的字段方向类型。

// 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

另请参阅