Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
   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


C#
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);
Posted
Updated 16-Sep-15 3:28am
v4

1 solution

can you please edit your code? it is unreadable.

i tried to get it clearer, but such:
C#
roomlist = new List();
can't be correct, and i can't guess, how it should be.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900