gpt4 book ai didi

c# - 如何序列化自定义对象类型列表

转载 作者:行者123 更新时间:2023-12-03 21:55:47 24 4
gpt4 key购买 nike

我有这样的课

public class Record
{
public Int32 TotalTrail { get; set; }
public TimeSpan MyTimeSpan { get; set; }
public DateTime MyDateTime { get; set; }
}

我有一个列表来保存它的对象:

List<Record> _records;

然后当我想序列化列表时:

serializer.Serialize(stream, _records);

上面一行有一个运行时错误:

Cannot assign object of type System.Collections.Generic.List`1[[SimpleGame.Record, SimpleGame, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to an object of type SimpleGame.Record.

是不是因为我无法序列化列表?我该如何解决这个问题?

最佳答案

您必须为 List<Record> 类型创建序列化程序而不是 Record

关于c# - 如何序列化自定义对象类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10868319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com