Click here to Skip to main content
15,885,868 members
Articles / Programming Languages / XML

Using the XmlSerializer Attributes

Rate me:
Please Sign up or sign in to vote.
4.58/5 (51 votes)
28 Jun 2006CPOL8 min read 314.9K   4.9K   126  
How to serialize and de-serialize .NET objects and XML using the XmlSerializer and the serializer attributes.
using System;
using System.Collections;

namespace GameList {
	public class StatsCounter {
		private ArrayList tbl;

		public StatsCounter() {
			tbl = new ArrayList();
		}

		public void Add(string text) {
			bool found = false;
			foreach (Stat st in tbl) {
				if (st.Text.Equals(text)) {
					found = true;
					st.Count++;
					found = true;
					break;
				}
			}
			if (!found) {
				Stat s = new Stat(text, 1);
				tbl.Add(s);
			}
		}

		public Stat this[int i] {
			get { return (Stat)tbl[i]; }
		}

		public int Count {
			get { return tbl.Count; }
		}
	}

	public class Stat {
		private string text;
		private int count;
		public Stat(string text, int count) {
			this.text = text;
			this.count = count;
		}
		public string Text {
			get { return text; }
			set { text = value; }
		}
		public int Count {
			get { return count; }
			set { count = value; }
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) BoneSoft Software
United States United States
I've been in software development for more than a decade now. Originally with ASP 2.0 and VB6. I worked in Japan for a year doing Java. And have been with C# ever since.

In 2005 I founded BoneSoft Software where I sell a small number of developer tools.
This is a Organisation (No members)


Comments and Discussions