[WEBINAR] Application Acceleration: Faster Performance for End Users

Unary Operator

Definition - What does Unary Operator mean?

A unary operator, in C#, is an operator that takes a single operand in an expression or a statement. The unary operators in C# are +, -,!, ~, ++, -- and the cast operator.

The signature of the declaration of a unary operator includes the operator token and the type of parameter; it does not require the return type and the name of the parameter.

All the C# unary operators have predefined implementation that will be used by default in an expression. These unary operators can be overloaded in user-defined types with custom implementation by defining static member functions using the "operator" keyword.

Techopedia explains Unary Operator

The list of unary operators with their details includes:

  • Unary Plus Operator (+): The result of an operation on a numeric type is the value of the operand itself. This operator has been predefined for all numeric types.
  • Unary Minus Operator (-): This operator can be used to negate numbers of the integer, floating-point and decimal type.
  • Logical Complement (negation) Operator (!): This operator can be used only with operands of Boole type.
  • Bitwise Complement (negation) Operator (~): This operator can be used with integer, unit, long and ulong operand types. The result of the operation is a bitwise complement (inverse of the binary representation) of the operand.
  • Prefix Increment (++) and Decrement (--) Operator: The operand can be a variable, property access, or an indexer access. With an increment operator, the result of the operation for operands of integer type would be the value incremented by 1. With a decrement operator, the result would be the value decremented by 1 from the operand. The increment/decrement operator can also be used with postfix notation
  • Cast Operator: Used to build cast expressions for conversion to a given type. This operator is represented by the symbol, "T," where T is the type to which the operand or the result of the expression must be converted

This definition was written in the context of C#

Techopedia Deals

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
"Techopedia" on Twitter

Sign up for Techopedia's Free Newsletter!

Email Newsletter

Join thousands of others with our weekly newsletter

Free Whitepaper: The Path to Hybrid Cloud
Free Whitepaper: The Path to Hybrid Cloud:
The Path to Hybrid Cloud: Intelligent Bursting To Amazon Web Services & Microsoft Azure
Free E-Book: Public Cloud Guide
Free E-Book: Public Cloud Guide:
This white paper is for leaders of Operations, Engineering, or Infrastructure teams who are creating or executing an IT roadmap.
Free Tool: Virtual Health Monitor
Free Tool: Virtual Health Monitor:
Virtual Health Monitor is a free virtualization monitoring and reporting tool for VMware, Hyper-V, RHEV, and XenServer environments.
Free 30 Day Trial – Turbonomic
Free 30 Day Trial – Turbonomic:
Turbonomic delivers an autonomic platform where virtual and cloud environments self-manage in real-time to assure application performance.