Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

+ Operator (C# Reference)

The + operator can function as either a unary or a binary operator.

Unary + operators are predefined for all numeric types. The result of a unary + operation on a numeric type is just the value of the operand.

Binary + operators are predefined for numeric and string types. For numeric types, + computes the sum of its two operands. When one or both operands are of type string, + concatenates the string representations of the operands.

Delegate types also provide a binary + operator, which performs delegate concatenation.

User-defined types can overload the unary + and binary + operators. Operations on integral types are generally allowed on enumeration. For more information, see operator (C# Reference).

class Plus
{
    static void Main()
    {
        Console.WriteLine(+5);        // unary plus
        Console.WriteLine(5 + 5);     // addition
        Console.WriteLine(5 + .5);    // addition
        Console.WriteLine("5" + "5"); // string concatenation
        Console.WriteLine(5.0 + "5"); // string concatenation 
        // note automatic conversion from double to string
    }
}
/*
Output:
5
10
5.5
55
55
*/

For more information, see the following sections in the C# Language Specification:

  • 1.6.7.5 Operators

  • 7.2 Operators

Community Additions

ADD
Show:
© 2015 Microsoft