英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论