What does =+ mean and why does it compile?

c#, operators

Solution

The `+` operator can be used as a binary or a unary operator. From MSDN:

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.

You can overload this operator for custom types, but for the built-in numeric types, this is essentially a no-op.

Problem

I've got the following typo: ``` subcomponentGroupCount = +subcomponentCount; ``` used in the following: ``` int subcomponentGroupCount = 0; foreach (Subcomponent subcomponent in group.Subcomponents) { int subcomponentCount = task.TaskDevice.TaskDeviceSubcomponents.Count(tds => tds.TemplateID == subcomponent.TemplateID); subcomponentGroupCount = +subcomponentCount; } ``` I intended it to be +=, but I'm left wondering what "= +var" means..

Original source