【发布时间】:2020-10-24 14:49:23
【问题描述】:
class GraphData {
List <double> closingPricesBTC = [];
List <double> closingPricesETH = [];
List <double> closingPricesLTC = [];
for (String cryptoCurrency in cryptoAbbreviation){
.
. (some code)
.
double closePrice = ....
closingPrices.add(closePrice);
}
}
cryptAbbreviation 在哪里
const List<String> cryptoAbbreviation = ['BTC', 'ETH', 'LTC'];
如何将当前的“加密货币”字符串附加到 closingPrices.add(closePrice) 的变量名称中,以便最终得到 closingPricesBTC.add(closePrice)、closingPricesETH.add(closePrice) 和 closingPricesLTC.add(closePrice)
我尝试过closingPrices$cryptoCurrency.add(closePrice);,但这不起作用。
【问题讨论】:
-
在 Java 中,您不能在运行时即时“编造”变量名。
-
它在颤振中也不起作用
-
这里要做的是将您的
List<Double>s(不是List<double>)放在Map<String, List<Double>>中,并以缩写作为键。 -
@KevinAnderson,是的,我在写同样的答案
标签: java flutter variables naming