【问题标题】:adding integers together in a function在函数中将整数相加
【发布时间】:2022-11-19 00:29:27
【问题描述】:

当用户使用该应用程序时,我有三个整数会发生变化。我正在尝试设置一个函数,在后台将它们被动地加在一起,并将 a 输出到我创建的另一个 int。所以我可以在 if else 语句中使用它来检查它是否大于或小于另一个 int。我可以将它设置为在用户按下按钮时工作,但是有没有办法被动地做到这一点?这是我的功能:

int calculateLeftTotalVP(){return movpLeftCounter + totalTOLeftCounter + paintedLeftCounter = totalVPLeft;}

我收到错误消息:缺少选择器,例如“.identifier”或“[0]”。尝试添加一个选择器。

在我试图加在一起的 3 个整数下。

请问最好的方法是什么?干杯

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我想你想要这样

    int calculateLeftTotalVP() {
      return totalVPLeft =
          movpLeftCounter + totalTOLeftCounter + paintedLeftCounter;
    }
    

    我更喜欢传递变量然后从中返回结果。

    int calculateLeftTotalVP({
      required int movpLeftCounter,
      required int totalTOLeftCounter,
      required int paintedLeftCounter,
    }) {
      return movpLeftCounter + totalTOLeftCounter + paintedLeftCounter;
    }
    
    totalVPLeft = calculateLeftTotalVP(movpLeftCounter: ,paintedLeftCounter: ,totalTOLeftCounter: );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-13
      • 2021-02-22
      • 2019-08-12
      • 1970-01-01
      相关资源
      最近更新 更多