首页  >  文章  >  后端开发  >  c# .net 将List序列化

c# .net 将List序列化

巴扎黑
巴扎黑原创
2016-12-19 17:13:572125浏览

/// <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());
        }

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn