Dart – 如何在方法参数中解构记录?

huangapple go评论49阅读模式
英文:

Dart - How to destructure a record in method parameters?

问题

我有这个方法:

void myMethod((String, int) record) {
  final (s, i) = record;
  // ...
}

我想直接在方法参数中解构记录。例如,类似这样:

void myMethod((String, int) (s, i)) {
  // ...
}

如何实现这个目标?

英文:

I have this method:

void myMethod((String, int) record) {
  final (s, i) = record;
  // ...
}

I would like to destructure the record in the method parameters directly. For example, something like:

void myMethod((String, int) (s, i)) {
  // ...
}

How can it be done?

答案1

得分: 1

这在Dart 3.0中目前不可行,但这是Dart语言问题跟踪器上正在讨论的一个改进建议:https://github.com/dart-lang/language/issues/3001

英文:

This is not possible right now in Dart 3.0, but it is something that is being discussed on the Dart language issue tracker as an suggestion for improvement: https://github.com/dart-lang/language/issues/3001

huangapple
  • 本文由 发表于 2023年7月18日 09:56:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定