Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
.NET Framework Class Library
BinaryExpression Class

Updated: November 2007

Represents an expression that has a binary operator.

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

Visual Basic (Declaration)
Public NotInheritable Class BinaryExpression _
    Inherits Expression
Visual Basic (Usage)
Dim instance As BinaryExpression
C#
public sealed class BinaryExpression : Expression
Visual C++
public ref class BinaryExpression sealed : public Expression
J#
public final class BinaryExpression extends Expression
JScript
public final class BinaryExpression extends Expression

The following tables summarize the factory methods that can be used to create a BinaryExpression that has a specific node type, represented by the NodeType property. Each table contains information for a specific class of operations such as arithmetic or bitwise.

Binary Arithmetic Operations

Bitwise Operations

Node Type

Factory Method

And

And

Or

Or

ExclusiveOr

ExclusiveOr

Shift Operations

Node Type

Factory Method

LeftShift

LeftShift

RightShift

RightShift

Conditional Boolean Operations

Node Type

Factory Method

AndAlso

AndAlso

OrElse

OrElse

Comparison Operations

Coalescing Operations

Node Type

Factory Method

Coalesce

Coalesce

Array Indexing Operations

Node Type

Factory Method

ArrayIndex

ArrayIndex

In addition, the MakeBinary methods can also be used to create a BinaryExpression. These factory methods can be used to create a BinaryExpression of any node type that represents a binary operation. The parameter of these methods that is of type NodeType specifies the desired node type.

The following example creates a BinaryExpression object that represents the subtraction of one number from another.

Visual Basic
' Create a BinaryExpression that represents subtracting 14 from 53.
Dim binaryExpression As System.Linq.Expressions.BinaryExpression = _
    System.Linq.Expressions.Expression.MakeBinary( _
        System.Linq.Expressions.ExpressionType.Subtract, _
        System.Linq.Expressions.Expression.Constant(53), _
        System.Linq.Expressions.Expression.Constant(14))

Console.WriteLine(binaryExpression.ToString())

' This code produces the following output:
'
' (53 - 14)

C#
// Create a BinaryExpression that represents subtracting 14 from 53.
System.Linq.Expressions.BinaryExpression binaryExpression =
    System.Linq.Expressions.Expression.MakeBinary(
        System.Linq.Expressions.ExpressionType.Subtract,
        System.Linq.Expressions.Expression.Constant(53),
        System.Linq.Expressions.Expression.Constant(14));

Console.WriteLine(binaryExpression.ToString());

// This code produces the following output:
//
// (53 - 14)

System..::.Object
  System.Linq.Expressions..::.Expression
    System.Linq.Expressions..::.BinaryExpression
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 Vista, Windows XP SP2, 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker