gpt4 book ai didi

c# - List 到 List C#
转载 作者:行者123 更新时间:2023-11-30 19:10:43 24 4
gpt4 key购买 nike

我用谷歌搜索并看到转换为 List<Object> .但我认为我的情况有所不同。我有以下内容:

public class Entry
{
[XmlText]
public string DataLogEntry { get; set; }
}

并像这样使用:

public class EndLot
{
[XmlElement("Entry")]
public List<Entry> Items;
}

所以如果我有字符串列表,即。

List<string> EndLotLines

如何创建 EndLot 的实例有了这份名单。我正在尝试:

List<Entry> Items =  (List<Entry>)EndLotLines;       

最佳答案

使用 Linq 的 Select方法:

var items = EndLotLines.Select(s => new Entry { DataLogEntry = s }).ToList();

关于c# - List<String> 到 List<Object> C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16024891/

24 4 0