Dynamically build an array for web service

后端 未结 5 963
既然无缘
既然无缘 2021-01-27 01:55

I\'m using C# and asp.net to query a web service.

The user will enter the number of guests and then I need to add that number of guests to the web service call. Creati

5条回答
  •  鱼传尺愫
    2021-01-27 02:20

    Instead of using a raw array why not use ArrayList or List?

    var list = new List();
    adult.Id = 1;
    adult.Title = "Mr";
    adult.Firstname = "Test";
    adult.Surname = "Test";
    list.Add(adult);
    
    Guest adult2 = new Guest();
    adult2.Id = 2;
    adult2.Title = "Mr";
    adult2.Firstname = "Test";
    adult2.Surname = "Test";
    list.Add(adult2);
    
    Guest[] adults = list.ToArray();
    

    提交回复
    热议问题