Expression.Return Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Cria um GotoExpression que representa uma instrução return.
Sobrecargas
| Name | Description |
|---|---|
| Return(LabelTarget) |
Cria um GotoExpression que representa uma instrução return. |
| Return(LabelTarget, Expression) |
Cria um GotoExpression que representa uma instrução return. O valor passado para a etiqueta ao saltar pode ser especificado. |
| Return(LabelTarget, Type) |
Cria um GotoExpression que representa uma instrução return com o tipo especificado. |
| Return(LabelTarget, Expression, Type) |
Cria um GotoExpression que representa uma instrução return com o tipo especificado. O valor passado para a etiqueta ao saltar pode ser especificado. |
Return(LabelTarget)
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
Cria um GotoExpression que representa uma instrução 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
Parâmetros
- target
- LabelTarget
O LabelTarget que vai GotoExpression saltar para.
Devoluções
A GotoExpression com Kind igual a Return, a Target propriedade definida em target, e um valor nulo a ser passado para a etiqueta de destino ao saltar.
Aplica-se a
Return(LabelTarget, Expression)
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
Cria um GotoExpression que representa uma instrução return. O valor passado para a etiqueta ao saltar pode ser especificado.
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
Parâmetros
- target
- LabelTarget
O LabelTarget que vai GotoExpression saltar para.
- value
- Expression
O valor que será passado para a etiqueta associada ao saltar.
Devoluções
A GotoExpression com Kind igual a Continue, a Target propriedade definida para target, e value a ser passada para a etiqueta de destino ao saltar.
Exemplos
O exemplo seguinte demonstra como criar uma expressão que contenha o Return método.
// 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).
Aplica-se a
Return(LabelTarget, Type)
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
Cria um GotoExpression que representa uma instrução return com o tipo especificado.
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
Parâmetros
- target
- LabelTarget
O LabelTarget que vai GotoExpression saltar para.
Devoluções
A GotoExpression com Kind igual a Return, a Target propriedade definida para target, a Type propriedade definida para type, e um valor nulo a ser passado para a etiqueta alvo ao saltar.
Aplica-se a
Return(LabelTarget, Expression, Type)
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
- Origem:
- GotoExpression.cs
Cria um GotoExpression que representa uma instrução return com o tipo especificado. O valor passado para a etiqueta ao saltar pode ser especificado.
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
Parâmetros
- target
- LabelTarget
O LabelTarget que vai GotoExpression saltar para.
- value
- Expression
O valor que será passado para a etiqueta associada ao saltar.
Devoluções
A GotoExpression com Kind igual a Continue, a Target propriedade definida para target, a Type propriedade definida para type, e value para ser passada para o rótulo alvo ao saltar.