请考虑以下代码.
void main() {
int num = 5;
print('The number is ' + num);
}
当我try 打印变量num的值时,得到异常:The argument type 'int' can't be assigned to the parameter type 'String'
.
我该怎么做呢?
请考虑以下代码.
void main() {
int num = 5;
print('The number is ' + num);
}
当我try 打印变量num的值时,得到异常:The argument type 'int' can't be assigned to the parameter type 'String'
.
我该怎么做呢?
为了将int的值与字符串一起打印,您需要使用字符串插值:
void main() {
int num = 5;
print("The number is $num");
}