Sean Anderson
Sean Anderson

Reputation: 29301

What does =+ mean and why does it compile?

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..

Upvotes: 5

Views: 98

Answers (1)

p.s.w.g
p.s.w.g

Reputation: 149030

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.

Upvotes: 9

Related Questions