Comma Operator

Summary

Evaluates a series of expressions and returns the value of the last evaluated expression.

Syntax

expression1,  expression2 [, expression3 [, ...  expressionN ] ]

Parameters

expressionN
Any legal expression.

Description

When used in an expression, the comma operator evaluates a series of sub-expressions (separated by the comma operator) from left to right and returns the value of the last (rightmost) evaluated expression.

Examples

Basic Usage
1
2
3
4
5
import System;
 
int a = (1, 2, 3);
 
Console.log(a); // 3
Update Multiple for Loop Counters
1
2
3
4
5
6
7
import System;
 
int[][] array = [ [ 1, 2 ], [ 3, 4, 5 ] ];
 
for (int i = 0, j = 1; i <= 15; i++, j++) {
    Console.log(array[i][j]);
}

Share

HTML | BBCode | Direct Link