Return multiple values from function

前端 未结 4 509
抹茶落季
抹茶落季 2021-01-01 08:28

Is there a way to return several values in a function return statement (other than returning an object) like we can do in Go (or some other languages)?

For example,

4条回答
  •  执念已碎
    2021-01-01 09:22

    Dart doesn't support multiple return values.

    You can return an array,

    List foo() {
      return [42, "foobar"];
    }
    

    or if you want the values be typed use a Tuple class like the package https://pub.dartlang.org/packages/tuple provides.

    See also either for a way to return a value or an error.

提交回复
热议问题