我用谷歌搜索并看到转换为 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/