Rumah > Artikel > pembangunan bahagian belakang > c# .net 将List序列化
/// <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()); }