In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.