📜  在 dart 代码示例中通过引用传递

📅  最后修改于: 2022-03-11 14:48:06.510000             🧑  作者: Mango

代码示例1
//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
}