UnaryExpression Class

Represents an expression that has a unary operator.

Namespace:  System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

public sealed class UnaryExpression : 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 
// 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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft