欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

c# .net 将List序列化

程序员文章站 2022-04-14 14:13:42
...
/// <summary>
        /// 序列化List
        /// </summary>
        /// <param name="al"></param>
        /// <returns>string</returns>
        public string SerializeArrayList(ArrayList al)
        {
            Type[] extra = new Type[1];
            extra[0] = typeof(LocalNetInfo);
           // extra[0] = typeof(string);
            XmlSerializer xs = new XmlSerializer(typeof(ArrayList), extra);
            MemoryStream ms = new MemoryStream();
            XmlTextWriter tw = new XmlTextWriter(ms, Encoding.Default);
            xs.Serialize(tw, al);
            tw.Close();
            return Encoding.Default.GetString(ms.ToArray());
        }