Assignment Operators

Tags: Dissertation Proposals300 Word Essay SampleCritical Essay On FilmBest Schools For Creative WritingWriting Pages OnlineDissertation Coaching

It's one operator symbol so don't put blanks between the and =. Current compilers translate them into equivalent code, so there's no efficiency difference, unlike early C compilers where was more efficient.

With this notation it isn't necessary to repeat the variable that is being assigned to. This notation can also be used with the bit operators (^, &, |).

Compound-assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. *= assigns the result of the multiplication /= assigns the result of the division.

They perform the operation on the two operands before assigning the result to the first operand.

It can not be used with the logical short-circuit operators && and ||, but you can use the & and | versions.

It can only be used with binary (two operand) operators, not unary operators.For simple variables, which kind of assignment to use is mainly a style or readability difference.However, when assigning to l-values that require computation, there is a real difference, both in performance and possible side-effects.This system can be used to declare a new type, and define an assignment for that type.For instance, to be able to assign a newly defined type ’Complex’ The assignment operator is also used to convert types from one type to another.In other words, compound operators can't be used to declare a new variable.Like the “=” assignment operator, compound operators return the assigned result of the expression: // Simple assignment int x = 5; // x is 5 // Incrementation x = 5; // x is 10 // Decrementation x -= 2; // x is 8 // Multiplication x *= 2; // x is 16 // Modulus x %= 3; // x is 1 // Binary AND x &= 4; // x is 0 // Binary exclusive OR x ^= 4; // x is 4 // Binary inclusive OR x |= 8; // x is 12 As we can see here, the syntax to use these operators is consistent.If you observe above example, we defined a variable or operand “x” and assigning a new values to that variable by using assignment operators in c# programming language.When we execute above c# program, we will get the result like as shown below.If you observe above sample we defined a variable called “a” and assigned a new value using assignment operator (=) based on our requirements.Following table lists the different type of operators available in c# assignment operators.


Comments Assignment Operators

The Latest from ©