Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Assignment
Assignment statement

An assignment statement assigns an instance to the lvalue.


Table of contents:


Format

Lvalue

Assignment symbol =

Expression

Semicolon

Example

Format

The format of the assignment statement is:


lvalue = expression ;


The lvalue is things that can be placed on the left side of the assignment symbol. In Rice, they are variables, fields , expressions that end with a setter , and expressions that end with an indexer operator.

The lvalue will be changed with an instance returned by the expression on the right-hand side of the assignment symbol.


If the lvalue ends with a variable or field, changes the address referenced by the lvalue.

If the lvalue ends with a setter, it is converted to a setter call.

If the lvalue ends with an indexer operator, changes an item of corresponding list class.

Lvalue

The lvalue is things that can be placed on the left side of the assignment symbol.In Rice, they are variables, fields, expressions that end with a setter, and expressions that end with an indexer operator.

Assignment symbol =

It is a symbol for changing the lvalue.

Expression

The expression creates an instance that changes the lvalue. The class of the generated instance must be the same as the lvalue.

As an exception, when assigning a numeric class with a small range to a numeric class with a large range, you can assign even if both classes are different.


real rr;

rr = 10L; // Assigns the long value to the real.

rr = 10; // Assigns the int value to the real.

long ll;

ll = 10; // Assigns the int value to the long.


In this case, a new instance of the lvalue class is created based on the instance returned by the right side, and it is assigned.

Semicolon

The end of a assignment statement is represented by a semicolon.

Example

1:

class example

2:

int var1;

3:

closed setter VarSetter(int val)

4:

var1 = val; // ♦1

5:

es

6:

open method void someMethod(int arg)

7:

this.VarSetter = arg; // ♦2

8:

em

9:

ec

♦1 : Lvalue is the field.

♦2 : Lvalue is the expression that ends with the setter.

Next
Previous
Copyright © Rice All rights reserved.