Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

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
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pass #reference #dart
ADD COMMENT
Topic
Name
2+9 =