Expression.Return Metodo
In questo articolo
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Crea un oggetto GotoExpression che rappresenta un'istruzione return.
Return(LabelTarget) |
Crea un oggetto GotoExpression che rappresenta un'istruzione return. |
Return(LabelTarget, Expression) |
Crea un oggetto GotoExpression che rappresenta un'istruzione return. Il valore passato all'etichetta al momento del passaggio può essere specificato. |
Return(LabelTarget, Type) |
Crea un oggetto GotoExpression che rappresenta un'istruzione return con il tipo specificato. |
Return(LabelTarget, Expression, Type) |
Crea un oggetto GotoExpression che rappresenta un'istruzione return con il tipo specificato. Il valore passato all'etichetta al momento del passaggio può essere specificato. |
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
Crea un oggetto GotoExpression che rappresenta un'istruzione return.
public:
static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target);
public static System.Linq.Expressions.GotoExpression Return (System.Linq.Expressions.LabelTarget target);
static member Return : System.Linq.Expressions.LabelTarget -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget) As GotoExpression
Parametri
- target
- LabelTarget
Oggetto LabelTarget a cui passerà l'oggetto GotoExpression.
Restituisce
Oggetto GotoExpression con la proprietà Kind uguale a Return, la proprietà Target impostata su target
e un valore Null da passare all'etichetta di destinazione al momento del passaggio.
Si applica a
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
Crea un oggetto GotoExpression che rappresenta un'istruzione return. Il valore passato all'etichetta al momento del passaggio può essere specificato.
public:
static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ value);
public static System.Linq.Expressions.GotoExpression Return (System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression value);
public static System.Linq.Expressions.GotoExpression Return (System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression? value);
static member Return : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget, value As Expression) As GotoExpression
Parametri
- target
- LabelTarget
Oggetto LabelTarget a cui passerà l'oggetto GotoExpression.
- value
- Expression
Valore che al momento del passaggio verrà passato all'etichetta associata.
Restituisce
Oggetto GotoExpression con la proprietà Kind uguale a Continue, la proprietà Target impostata su target
e value
da passare all'etichetta di destinazione al momento del passaggio.
Esempio
Nell'esempio seguente viene illustrato come creare un'espressione contenente il Return metodo .
// Add the following directive to the file:
// using System.Linq.Expressions;
// A label expression of the void type that is the target for Expression.Return().
LabelTarget returnTarget = Expression.Label();
// This block contains a GotoExpression that represents a return statement with no value.
// It transfers execution to a label expression that is initialized with the same LabelTarget as the GotoExpression.
// The types of the GotoExpression, label expression, and LabelTarget must match.
BlockExpression blockExpr =
Expression.Block(
Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("Return")),
Expression.Return(returnTarget),
Expression.Call(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }), Expression.Constant("Other Work")),
Expression.Label(returnTarget)
);
// The following statement first creates an expression tree,
// then compiles it, and then runs it.
Expression.Lambda<Action>(blockExpr).Compile()();
// This code example produces the following output:
//
// Return
// "Other Work" is not printed because
// the Return expression transfers execution from Expression.Return(returnTarget)
// to Expression.Label(returnTarget).
' Add the following directive to the file:
' Imports System.Linq.Expressions
' A label expression of the void type that is the target for Expression.Return().
Dim returnTarget As LabelTarget = Expression.Label()
' This block contains a GotoExpression that represents a return statement with no value.
' It transfers execution to a label expression that is initialized with the same LabelTarget as the GotoExpression.
' The types of the GotoExpression, label expression, and LabelTarget must match.
Dim blockExpr As BlockExpression =
Expression.Block(
Expression.Call(GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}), Expression.Constant("Return")),
Expression.Return(returnTarget),
Expression.Call(GetType(Console).GetMethod("WriteLine", New Type() {GetType(String)}), Expression.Constant("Other Work")),
Expression.Label(returnTarget)
)
' The following statement first creates an expression tree,
' then compiles it, and then runs it.
Expression.Lambda(Of Action)(blockExpr).Compile()()
' This code example produces the following output:
'
' Return
' "Other Work" is not printed because
' the Return expression transfers execution from Return(returnTarget)
' to Expression.Label(returnTarget).
Si applica a
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
Crea un oggetto GotoExpression che rappresenta un'istruzione return con il tipo specificato.
public:
static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target, Type ^ type);
public static System.Linq.Expressions.GotoExpression Return (System.Linq.Expressions.LabelTarget target, Type type);
static member Return : System.Linq.Expressions.LabelTarget * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget, type As Type) As GotoExpression
Parametri
- target
- LabelTarget
Oggetto LabelTarget a cui passerà l'oggetto GotoExpression.
Restituisce
Oggetto GotoExpression con la proprietà Kind uguale a Return, la proprietà Target impostata su target
, la proprietà Type impostata su type
e un valore Null da passare all'etichetta al momento del passaggio.
Si applica a
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
- Origine:
- GotoExpression.cs
Crea un oggetto GotoExpression che rappresenta un'istruzione return con il tipo specificato. Il valore passato all'etichetta al momento del passaggio può essere specificato.
public:
static System::Linq::Expressions::GotoExpression ^ Return(System::Linq::Expressions::LabelTarget ^ target, System::Linq::Expressions::Expression ^ value, Type ^ type);
public static System.Linq.Expressions.GotoExpression Return (System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression value, Type type);
public static System.Linq.Expressions.GotoExpression Return (System.Linq.Expressions.LabelTarget target, System.Linq.Expressions.Expression? value, Type type);
static member Return : System.Linq.Expressions.LabelTarget * System.Linq.Expressions.Expression * Type -> System.Linq.Expressions.GotoExpression
Public Shared Function Return (target As LabelTarget, value As Expression, type As Type) As GotoExpression
Parametri
- target
- LabelTarget
Oggetto LabelTarget a cui passerà l'oggetto GotoExpression.
- value
- Expression
Valore che al momento del passaggio verrà passato all'etichetta associata.
Restituisce
Oggetto GotoExpression con la proprietà Kind uguale a Continue, la proprietà Target impostata su target
, la proprietà Type impostata su type
e value
da passare all'etichetta di destinazione al momento del passaggio.