加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将对象列表保存到XML文件并使用C#加载该列表的最佳方法是什么?

发布时间:2020-12-16 23:09:02 所属栏目:百科 来源:网络整理
导读:我的应用程序中有一个“Gesture”类列表: ListGesture gestures = new ListGesture(); 这些手势类非常简单: public class Gesture{ public String Name { get; set; } public ListPoint Points { get; set; } public ListPoint TransformedPoints { get; s
我的应用程序中有一个“Gesture”类列表:

List<Gesture> gestures = new List<Gesture>();

这些手势类非常简单:

public class Gesture
{
    public String Name { get; set; }
    public List<Point> Points { get; set; }
    public List<Point> TransformedPoints { get; set; }    

    public Gesture(List<Point> Points,String Name)
    {
        this.Points = new List<Point>(Points);
        this.Name = Name;
    }
}

我想允许用户将“手势”的当前状态保存到文件中,并且还能够加载包含手势数据的文件.

在C#中执行此操作的标准方法是什么?

我应该使用序列化吗?我应该自己编写一个类来处理这个XML文件的编写/读取吗?还有其他方法吗?

解决方法

看一下.net中的XmlSerializer类型和XmlSerialization

在这里……找到了一个可以满足你需求的例子
http://www.switchonthecode.com/tutorials/csharp-tutorial-xml-serialization

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读