In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to realize XML serialization of C#". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how to realize XML serialization of C#" together!
C#XML serialization implementation example: Suppose there is a class
public class Person { public Person(string Name,string ID) { name=Name; id=ID; } public string name; public string id; }
C#XML serializes an existing entity
Person person1=new Person("abc","1234");
To serialize it, simply
XmlSerializer s = new XmlSerializer(typeof(Person )); TextWriter w = new StreamWriter( "person1.xml" ); s.Serialize(w, person1); w.Close();
You don't even have to worry about what the generated XML looks like. When you need to read it back
TextReader r = new StreamReader( "person1.xml" ); Person person2= (Person)s.Deserialize( r ); r.Close();
Now if you look at the list, it hasn't changed much.
List people=new List(); people.Add(new Person("abc","123")); people.Add(new Person("def","123")); XmlSerializer s = new XmlSerializer(List); s.Serialize(Console.Out, people);
In a slightly more complicated case, there is now an ArrayList to serialize.
ArrayList people=new ArrayList(); people.Add(new Person("abc","123")); people.Add(new Person("def","123"));
You need to tell the system about arrays.
XmlSerializer s = new XmlSerializer(typeof(ArrayList), new Type[] { typeof(Person) }); s.Serialize(Console.Out, people); Thank you for reading, the above is the content of "How to realize XML serialization of C#". After studying this article, I believe that everyone has a deeper understanding of how to realize XML serialization of C#. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.