我正在使用彭博社的C#网络服务代码来下载投资信息。
我正在努力找出使用字符串数组同时下载多个仪器的正确方法。instruments类的instrument成员是instruments对象的数组。您必须为请求的每个仪器创建一个单独的仪器对象,并将每个对象添加到数组中。然而,我仍然是C#的新手,我正在努力寻找正确的方法将多个instrument对象添加到instruments类中。下面的代码只是返回数组中的最后一次投资,因为循环中的最后一行似乎替换了先前的投资对象。
任何帮助都是非常感谢的。
谢谢。
string[] investments = { "BBG000BHGCD1", "BBG000BB2PW9" };
Instruments instruments = new Instruments();
foreach (string inv in investments)
{
Instrument instr = new Instrument();
instr.id = inv;
instr.yellowkeySpecified = false;
instr.typeSpecified = true;
instr.type = InstrumentType.BB_GLOBAL;
instruments.instrument = new Instrument[] { instr };
}
// Submitting request
SubmitGetActionsRequest req = new SubmitGetActionsRequest();
req.headers = getActionHeaders;
req.instruments = instruments;
submitGetActionsRequestRequest subGetActReqReq = new
submitGetActionsRequestRequest(req);发布于 2019-02-14 05:58:45
将您的循环更改为:
Instruments instruments = new Instruments();
var myList = new List<Instrument>();
foreach (string inv in investments)
{
myList.Add(new Instrument
{
id = inv,
yellowkeySpecified = false,
typeSpecified = true,
type = InstrumentType.BB_GLOBAL
});
}
instruments.instrument = myList.ToArray();https://stackoverflow.com/questions/54680023
复制相似问题