gpt4 book ai didi

flutter - 是否应在Dart中的方法输入参数中添加下划线(_)前缀?

转载 作者:行者123 更新时间:2023-12-03 04:26:36 25 4
gpt4 key购买 nike

两者都可以编译,但是我不知道哪个版本正确?

  int add(int _a, int _b) {
return _a + _b;
}

要么
  int add(int a, int b) {
return a + b;
}

最佳答案

根据Effective Dart

There is no concept of “private” for local variables, parameters, or library prefixes. When one of those has a name that starts with an underscore, it sends a confusing signal to the reader. To avoid that, don’t use leading underscores in those names.



因此,根据以下准则,代码更正确,
 int add(int a, int b) {
return a + b;
}

关于flutter - 是否应在Dart中的方法输入参数中添加下划线(_)前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59404190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com