将列表序列化到memorystream [英] Serialize a list to memorystream

查看:111
本文介绍了将列表序列化到memorystream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个List< string>我想序列化到内存流.能做到吗?

I've got a List<string> that I'm wanting to serialize to memorystream.  Can that be done?

列表< string> mylist = new List< string>();
mylist.Add(一个项目");
mylist.Add(列表中的两个项目");
mylist.Add(这是列表中的第三项");

List<string> mylist = new List<string>();
mylist.Add("One item");
mylist.Add("Two items in the list");
mylist.Add("This is the third item in the list");

推荐答案

您可以序列化到任何流.您需要确定要序列化为哪种格式.您可以直接使用XML或二进制文件.如果需要互操作,那么XML是一个不错的选择.如果您只需要在应用程序的运行过程中保留数据,则二进制文件是 清洁工.使用 XmlSerializer DataContractSerializer 以使用XML或

You can serialize to any stream.  What you need to decide is what format to serialize to. You can use XML or binary out of the box. If you need interop then XML is a good choice. If you only need to persist data across runs of your app then binary is cleaner. Use XmlSerializer or DataContractSerializer to serialize using XML or BinaryFormatter for binary.  In all cases they require you give them a Stream to write to (or read from). This can be a MemoryStream if desired.

迈克尔·泰勒
http://www.michaeltaylorp3.net

Michael Taylor
http://www.michaeltaylorp3.net


这篇关于将列表序列化到memorystream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆