Represents an expression that has a unary operator.
Namespace:
System.Linq.Expressions
Assembly:
System.Core (in System.Core.dll)
Visual Basic (Declaration)
Public NotInheritable Class UnaryExpression _
Inherits Expression
Dim instance As UnaryExpression
public sealed class UnaryExpression : Expression
public ref class UnaryExpression sealed : public Expression
public final class UnaryExpression extends Expression
The following table summarizes the factory methods that can be used to create a UnaryExpression that has a specific node type.
In addition, the MakeUnary methods can also be used to create a UnaryExpression. These factory methods can be used to create a UnaryExpression of any node type that represents a unary operation. The parameter of these methods that is of type NodeType specifies the desired node type.
The following example creates a UnaryExpression object that represents the reference conversion of a non-nullable integer expression to the nullable integer type.
' Create a UnaryExpression that represents a reference
' conversion of an Integer to an Integer? (a nullable Integer).
Dim typeAsExpression As System.Linq.Expressions.UnaryExpression = _
System.Linq.Expressions.Expression.TypeAs( _
System.Linq.Expressions.Expression.Constant(34, Type.GetType("System.Int32")), _
Type.GetType("System.Nullable`1[System.Int32]"))
Console.WriteLine(typeAsExpression.ToString())
' This code produces the following output:
'
' (34 As Nullable`1)
// Create a UnaryExpression that represents a
// conversion of an int to an int?.
System.Linq.Expressions.UnaryExpression typeAsExpression =
System.Linq.Expressions.Expression.TypeAs(
System.Linq.Expressions.Expression.Constant(34, typeof(int)),
typeof(int?));
Console.WriteLine(typeAsExpression.ToString());
// This code produces the following output:
//
// (34 As Nullable`1)
System..::.Object
System.Linq.Expressions..::.Expression
System.Linq.Expressions..::.UnaryExpression
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5
Reference