docs

#E0056: 無效的索引

這個值不能索引,或索引不是整數。陣列、串列和切片以整數索引,實作了 Index 的型別則以其鍵索引。

nabi
let total = 120;
println(f"{total[0]}");
error[E0056]: cannot index into a value of type `i64`
  --> main.nabi:2:12
   |
 2 | println(f"{total[0]}");
   |            ^^^^^^^^

對集合進行索引:

nabi
let totals = [120, 80];
println(f"{totals[0]}");
120

相關錯誤碼:E0040 型別不符

發現錯誤? 在 GitHub 上編輯此頁 最後更新: