Share via


CodeMethodReturnStatement 類別

定義

表示傳回值陳述式。

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

範例

下列範例示範如何使用 CodeMethodReturnStatement 從方法傳回值。

// 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 可以用來表示傳回值語句。 屬性 Expression 會指定要傳回的值。

建構函式

CodeMethodReturnStatement()

初始化 CodeMethodReturnStatement 類別的新執行個體。

CodeMethodReturnStatement(CodeExpression)

使用指定的運算式,初始化 CodeMethodReturnStatement 類別的新執行個體。

屬性

EndDirectives

取得包含結尾指示詞的 CodeDirectiveCollection 物件。

(繼承來源 CodeStatement)
Expression

取得或設定傳回值。

LinePragma

取得或設定程式碼陳述式發生所在的行。

(繼承來源 CodeStatement)
StartDirectives

取得包含開頭指示詞的 CodeDirectiveCollection 物件。

(繼承來源 CodeStatement)
UserData

取得目前物件的使用者可定義資料。

(繼承來源 CodeObject)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於