.net lList<EquipmentAccessoryStockLog>.add(List<EquipmentAccessoryStockLog>) 给出代码示例
时间: 2024-02-16 09:03:50 浏览: 60
以下是一个简单的示例代码,展示了如何使用List<EquipmentAccessoryStockLog>.Add()方法将一个装备配件库存日志列表添加到另一个装备配件库存日志列表中:
```csharp
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// 创建两个装备配件库存日志列表
List<EquipmentAccessoryStockLog> list = new List<EquipmentAccessoryStockLog>();
list.Add(new EquipmentAccessoryStockLog { Id = 1, AccessoryName = "配件1" });
list.Add(new EquipmentAccessoryStockLog { Id = 2, AccessoryName = "配件2" });
List<EquipmentAccessoryStockLog> list1 = new List<EquipmentAccessoryStockLog>();
list1.Add(new EquipmentAccessoryStockLog { Id = 3, AccessoryName = "配件3" });
list1.Add(new EquipmentAccessoryStockLog { Id = 4, AccessoryName = "配件4" });
list.Add(list1); // 将list1添加到list中
Console.WriteLine("list:");
foreach (EquipmentAccessoryStockLog log in list)
{
Console.WriteLine($"Id: {log.Id}, AccessoryName: {log.AccessoryName}");
}
}
}
// 装备配件库存日志类
class EquipmentAccessoryStockLog
{
public int Id { get; set; }
public string AccessoryName { get; set; }
}
```
输出结果为:
```
Id: 1, AccessoryName: 配件1
Id: 2, AccessoryName: 配件2
Id: 3, AccessoryName: 配件3
Id: 4, AccessoryName: 配件4
```
可以看到,list1被作为一个整体添加到了list中,并且其中的装备配件库存日志被逐个添加到了list中。
阅读全文