Month: October, 2007

Passing immutable types by reference in Java and C#

12 October, 2007 (18:26) | Java, C#, Computer Science

To many, it should be obvious what the following code prints:

public static void main(String[] args){
int x=0;
SomeMethod(x);
System.out.println(x);
}

protected static void SomeMethod(int x){
x=1;
}

The code prints 0, because “int” is a native type and is passed by value. […]