Answers for "does dart have pass by reference"

0

pass by reference in dart

//Dart doesn't support pass by reference. You could try wrapping it in a class

class PrimitiveWrapper {
  var value;
  PrimitiveWrapper(this.value);
}

void alter(PrimitiveWrapper data) {
  data.value++;
}

main() {
  var data = new PrimitiveWrapper(5);
  print(data.value); // 5
  alter(data);
  print(data.value); // 6
}
Posted by: Guest on August-23-2020

Code answers related to "Dart"

Browse Popular Code Answers by Language