Stenway Developer Network

Operators

Arithmetic Operators

Unary minus operator for signed integers:

var r1 = -i
var r2 = -(-i)

Addition, subtraction, multiplication, division and modulus (remainder) operator:

var r1 = a + b
var r2 = a - b
var r3 = a * b
var r4 = a / b
var r5 = a % b

Multiplicative operators (*, /, %) precede the additive operators (+, -).

Arithmetic Overflow and Division By Zero

OverflowError

var a = int.MaxValue + 1

DivideByZeroError

var a = 0
var b = 100/a

Bitwise Operators

And, or, exclusice or (xor)

var r1 = a & b
var r2 = a | b
var r3 = a ^ b

Complement

var r = ~a

Left shift, right shift

var r1 = a << 4
var r2 = a >> 2

Boolean Operators

And, or, exclusice or (xor)

var r1 = a & b
var r2 = a | b
var r3 = a ^ b

Negation

var r = not a

Short-circuiting

var r1 = a and b
var r2 = a or b

String Operators

Concatenation

var r = a + b

Comparison Operators

Equality, inequality, greater than, less than, greater than or equal, less than or equal, pointer equality, pointer inequality

var r1 = a == b
var r2 = a != b
var r3 = a > b
var r4 = a < b
var r5 = a >= b
var r6 = a <= b

Pointer equality, pointer inequality

var r1 = a === b
var r2 = a !== b

Case-insensitive (simple ordinal) string equality

a ^== b

Null-Default Operator

var strA = null
var strB = strA ?? "Default value"
doSomething(strA ?? "Default value", 123)

Conditional Operator (Ternary)

var str = i > 2 ? "a" ! "b"
doSomething(i > 2 ? "a" ! "b", 123)

Member Access

Member access, index operator, safe navigation, safe index operator

var r1 = a.b
var r2 = a[b]
var r3 = a?.b
var r4 = a?[b]

Type Testing

Is

var str = "abc"
var b = str is int

Is not

namespace MyLib
  class MyClass
    method doSomething(o)
      if o is not string : return
      else
        Console.log(o)
      end
    end
  end
end

Name-Of

var myInt = 123
var str = nameof(myInt)

Type-Of

var type = typeof(MyClass)

Operator Precedence

()
a.b a[b] a?.b a?[b]
+a -a ~a
a*b a/b a%b
a+b a-b
a<<b a>>b
a&b
a^b
a|b
a<b a>b a<=b a>=b is "is not"
a==b a!=b a===b a!==b a^==b
not a
a&b
a^b
a|b
a and b
a or b
a??b
a?b!c