小编Sam*_*isa的帖子

如何在 Ballerina 中从命令行读取 int?

any choice = io:readln("Enter choice 1 - 5: ");
Run Code Online (Sandbox Code Playgroud)

我似乎无法将输入转换为 int。

检查和匹配都会给出相同的错误

var intChoice = <int>choice;
match intChoice {
    int value => c = value;
    error err => io:println("error: " + err.message);
}
Run Code Online (Sandbox Code Playgroud)

c = check <int>choice;
Run Code Online (Sandbox Code Playgroud)

给出

error: 'string' cannot be cast to 'int'
Run Code Online (Sandbox Code Playgroud)

我查看了https://ballerina.io/learn/by-example/type-conversion.html并研究了https://ballerina.io/learn/api-docs/ballerina/io.html#readln但没有运气。

我究竟做错了什么?

ballerina

6
推荐指数
1
解决办法
589
查看次数

标签 统计

ballerina ×1