Dart : Printing integer along with string

标签 dart concatenation string-concatenation

考虑下面的代码。

void main() {
  int num = 5;
  print('The number is ' + num);
}

当我尝试打印变量 num 的值时,出现异常:参数类型“int”无法分配给参数类型“String”

如何打印 num?

最佳答案

为了将 int 的值与 String 一起打印,您需要使用字符串插值:

void main() {
  int num = 5;
  print("The number is $num");
}

关于 Dart : Printing integer along with string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50885792/

相关文章:

android - FlutterView 未在 Android 中显示 Widget UI

python - python - 如何连接四舍五入数字的字符串?

c# - 是否加锁 : Parallel String Concatenation

flutter - Firestore queryBuilder中的多个where查询

Flutter 和 Angular Dart 都共享组件模式,但是这两个框架之间的一个根本区别是什么?

dart - 检查一个列表是否包含另一个列表的一个或多个值

google-sheets - 将某些行连接到单元格中,忽略重复项

c - 字符串文字的 strcat 与 strncat

javascript - 将 php 字符串连接到 javascript 字符串

C# 连接字符串以进行串行发送