The out keyword
out is similar to ref, but it is used to output a value from the method, meaning:
- The parameter cannot be read before it is assigned.
- The parameter must be assigned before the method returns.
public static void Increment(int current, out int next) {
next = current + 1;
}
Using out is similar to ref:
int x = 5; Increment(x, out x);