如何在使用c#的隐式类型数组中使用for循环 [英] how to use for loop in Implicitly Typed Arrays using c#
本文介绍了如何在使用c#的隐式类型数组中使用for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在下面的代码中使用c#在隐式类型数组中使用for循环。我需要在dynamic.already中循环遍历forloop中的roomList我也创建了一个列表
清单:
how to use for loop in Implicitly Typed Arrays using c#in below code.i need to loop through roomList in forloop in dynamic.already i created one list also
List:
public class Inventory
{
public Inventory()
{
roomlist = new List<roomtariff>();
}
public List<roomtariff> roomlist { get; set; }
}
public class RoomTariff
{
public string tarifSeq { get; set; }
public string roomSeq { get; set; }
public string tariffType { get; set; }
public string roomType { get; set; }
public string plan { get; set; }
}
我的代码
My code
for (int i = 0; i < child[0].roomlist.Count; i++)
{
var postdata = new
{
fromDate = fromdate,
toDate = todate,
hotelRequest = new
{
roomList = new[]
{
new { roomSeq = "54545", roomName = "A.c Room", tariffRequests = new[] { new { tarifSeq = "dfdf45b54", plan = "yu" } } },
new { roomSeq = "5454", roomName = "Del Room", tariffRequests = new[] { new { tarifSeq = "gdgfdg;l;gfd", plan = "Eu" } } },
new { roomSeq = "5422", roomName = "Suite Room", tariffRequests = new[] { new { tarifSeq = "fdght411", plan = "Euuu" } } },
new { roomSeq = "457", roomName = "Execu Room", tariffRequests = new[] { new { tarifSeq = "gfgfgf", plan = "tyt" } } },
new { roomSeq = "222", roomName = "NonRoom", tariffRequests = new[] { new { tarifSeq = "gfgfg", plan = "tyty" } } } }
},
datavisible = false
};
string requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(postdata);
推荐答案
你能编辑你的代码吗?它是不可读的。
i试图让它更清晰,但是这样:
can you please edit your code? it is unreadable.
i tried to get it clearer, but such:
roomlist = new List();
不能正确,我无法猜测它应该如何。
can't be correct, and i can't guess, how it should be.
这篇关于如何在使用c#的隐式类型数组中使用for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文