Return multiple values from function

前端 未结 4 505
抹茶落季
抹茶落季 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:11

    In this type of situation in Dart, an easy solution could return a list then accessing the returned list as per your requirement. You can access the specific value by the index or the whole list by a simple for loop.

    List func() {
      return [false, 30, "Ashraful"];
    }
    
    void main() {
      final list = func();
      
      // to access specific list item
      var item = list[2];
      
      // to check runtime type
      print(item.runtimeType);
      
      // to access the whole list
      for(int i=0; i

提交回复
热议问题