CodeMethodReturnStatement 类

定义

表示返回值语句。Represents a return value statement.

public ref class CodeMethodReturnStatement : System::CodeDom::CodeStatement
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeMethodReturnStatement : System.CodeDom.CodeStatement
type CodeMethodReturnStatement = class
    inherit CodeStatement
Public Class CodeMethodReturnStatement
Inherits CodeStatement
继承
CodeMethodReturnStatement
属性

示例

下面的示例演示CodeMethodReturnStatement如何使用从方法返回值。The following example demonstrates use of a CodeMethodReturnStatement to return a value from a method.

// Defines a method that returns a string passed to it.
CodeMemberMethod^ method1 = gcnew CodeMemberMethod;
method1->Name = "ReturnString";
method1->ReturnType = gcnew CodeTypeReference( "System.String" );
method1->Parameters->Add( gcnew CodeParameterDeclarationExpression( "System.String","text" ) );
method1->Statements->Add( gcnew CodeMethodReturnStatement( gcnew CodeArgumentReferenceExpression( "text" ) ) );

// A C# code generator produces the following source code for the preceeding example code:
//    private string ReturnString(string text) 
//    {
//        return text;
//    }
// Defines a method that returns a string passed to it.
CodeMemberMethod method1 = new CodeMemberMethod();            
method1.Name = "ReturnString";
method1.ReturnType = new CodeTypeReference("System.String");
method1.Parameters.Add( new CodeParameterDeclarationExpression("System.String", "text") );
method1.Statements.Add( new CodeMethodReturnStatement( new CodeArgumentReferenceExpression("text") ) );            

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

//    private string ReturnString(string text) 
//    {
//        return text;
//    }
' Defines a method that returns a string passed to it.
Dim method1 As New CodeMemberMethod()
method1.Name = "ReturnString"
method1.ReturnType = New CodeTypeReference("System.String")
method1.Parameters.Add(New CodeParameterDeclarationExpression("System.String", "text"))
method1.Statements.Add(New CodeMethodReturnStatement(New CodeArgumentReferenceExpression("text")))

' A Visual Basic code generator produces the following source code for the preceeding example code:

'   Private Function ReturnString(ByVal [text] As String) As String
'       Return [Text]
'   End Function

注解

CodeMethodReturnStatement可用于表示返回值语句。CodeMethodReturnStatement can be used to represent a return value statement. Expression属性指定要返回的值。The Expression property specifies the value to return.

构造函数

CodeMethodReturnStatement()

初始化 CodeMethodReturnStatement 类的新实例。Initializes a new instance of the CodeMethodReturnStatement class.

CodeMethodReturnStatement(CodeExpression)

使用指定的表达式初始化 CodeMethodReturnStatement 类的新实例。Initializes a new instance of the CodeMethodReturnStatement class using the specified expression.

属性

EndDirectives

获取包含结束指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains end directives.

(继承自 CodeStatement)
Expression

获取或设置返回值。Gets or sets the return value.

LinePragma

获取或设置代码语句所在的行。Gets or sets the line on which the code statement occurs.

(继承自 CodeStatement)
StartDirectives

获取包含开始指令的 CodeDirectiveCollection 对象。Gets a CodeDirectiveCollection object that contains start directives.

(继承自 CodeStatement)
UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于