c# - 为网络服务动态构建数组

标签 c# arrays web-services

我正在使用 C# 和 asp.net 查询 Web 服务。

用户将输入客人人数,然后我需要添加 guest 对 Web 服务调用的数量。像这样手动创建客人。

// Create room layout for searching

Guest adult = new Guest();
adult.Id = 1;
adult.Title = "Mr";
adult.Firstname = "Test";
adult.Surname = "Test";

Guest adult2 = new Guest();
adult2.Id = 2;
adult2.Title = "Mr";
adult2.Firstname = "Test";
adult2.Surname = "Test";

Guest[] adults = new Guest[] { adult,adult2 };

用户选择在我的网站上搜索的成人人数 页面,我不知道成人的数量,希望能够将他们动态添加到 Web 服务调用中。我将收到这样的成人人数

int numberofguests = Convert.ToInt32(search.Guest);

我尝试了很多方法,但无法让它工作

最佳答案

List<Guest> guests = new List<Guest>();
for(int i=0; i<numberOfGuests; i++)
{
  guests.Add(new Guest()
  {
    Title = "Mr",
    Firstname = "Test",
  });
}
return guests.ToArray();

关于c# - 为网络服务动态构建数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/735446/

相关文章:

c - 结构数组,无法检查条目是否为 NULL

java - 从 Web 应用程序并行调用许多不同的 Web 服务

c# - 在 FluentAssertions 中自定义失败处理

c# - Biztalk 在 C# 中接收位置

c# - 优化在 MySQL 中存储 Guid : "Data too long for column" even if it should fit to CHAR(16)

c# - EmguCV 3.0 中的 CvInvoke.ConvexityDefects()

python - 值错误 : zero-dimensional arrays cannot be concatenated

python - 如何仅增加 Python 列表中第一行的第一个元素?

java - 处理状态为 NO_CONTENT 的响应时的 Spring RestTemplate 行为

web-services - Delphi native Web 服务应用程序无法运行。 IIS 7 似乎正在剥离路径信息