Unary plus

  • Thread starter Thread starter Michael A. Covington
  • Start date Start date
M

Michael A. Covington

Other than to create confusion, does the unary plus operator serve any
purpose at all?

All C# numeric types have a unary plus. The syntax is something like:

x = +y;

where +y is the same value as y, whether positive or negative.
 
Well, you can use it to neatly line up positive and negative values in
a monospaced font... other than that I don't know!
 
Michael,

This is one of those things where any reference you care to hunt down
quotes the same exact definition, which tells me that no one has a
coherent explanation. It is probably an item of esoterica that's thrown
in for "completeness" from the perspective of the language designer, but
I can't think of a use for us mere mortals, except that tutorials feel
obligated to mention it because it's there ;-)

--Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top