Dart lambda/shortland function confusion

后端 未结 3 1690
时光取名叫无心
时光取名叫无心 2020-12-30 18:32

I\'m still pretty new to Dart and the syntax of => (fat arrow) still confuses me (I come from C# background).

So in C# fat arrow ( => ) says: goes to so for

3条回答
  •  Happy的楠姐
    2020-12-30 19:18

    In Dart => xxx is just a syntaxic sugar to avoid { return xxx; }. Thus the two following functions are equivalent :

    var a = (String s) => s;
    var b = (String s) { return s; } ;
    

    You can also use => on method definitions :

    String myFunc(String s) => s;
    String myFunc(String s) {
      return s;
    }
    

提交回复
热议问题