Click here to Skip to main content
15,894,405 members
Home / Discussions / C#
   

C#

 
GeneralRe: Desktop Control Pin
Heath Stewart23-Mar-04 18:08
protectorHeath Stewart23-Mar-04 18:08 
GeneralRe: Desktop Control Pin
Anonymous24-Mar-04 14:09
Anonymous24-Mar-04 14:09 
GeneralRe: Desktop Control Pin
Heath Stewart24-Mar-04 17:00
protectorHeath Stewart24-Mar-04 17:00 
GeneralDistinct - DataView/DataTable Pin
Ruchi Gupta23-Mar-04 13:57
Ruchi Gupta23-Mar-04 13:57 
GeneralRe: Distinct - DataView/DataTable Pin
Heath Stewart23-Mar-04 14:09
protectorHeath Stewart23-Mar-04 14:09 
GeneralRe: Distinct - DataView/DataTable Pin
Ruchi Gupta23-Mar-04 14:41
Ruchi Gupta23-Mar-04 14:41 
GeneralRe: Distinct - DataView/DataTable Pin
Heath Stewart23-Mar-04 18:00
protectorHeath Stewart23-Mar-04 18:00 
GeneralXML Serialization and ArrayLists Pin
raindog23-Mar-04 13:23
raindog23-Mar-04 13:23 
the following are my classes
Class Students.cs
<br />
using System;<br />
using System.Collections;<br />
using System.IO;<br />
using System.Runtime.Serialization;<br />
using System.Xml.Serialization;<br />
namespace WindowsApplication1<br />
{<br />
	/// <summary><br />
	/// Summary description for Students.<br />
	/// </summary><br />
	[Serializable]<br />
	public class Students<br />
	{<br />
		int index = 1;<br />
		ArrayList students = new ArrayList();<br />
		public Students()<br />
		{<br />
			//populate some students<br />
		}<br />
<br />
<br />
		public void AddStudent( string name, string add)<br />
		{<br />
			Student t = new Student(index++, name, add);<br />
			students.Add(t);<br />
		}<br />
		public void RemoveStudent(int sID)<br />
		{<br />
			foreach(Student s in students)<br />
			{<br />
				if (s.StudentID == sID)<br />
				{<br />
					students.Remove(s);<br />
					return;<br />
				}<br />
			}<br />
			return;<br />
		}<br />
<br />
		public ArrayList Items<br />
		{ get {return students;} }<br />
		<br />
		public Student this[int index]<br />
		{<br />
			get<br />
			{<br />
				foreach(Student s in students)<br />
				{<br />
					if(s.StudentID == index)<br />
						return s;<br />
				}<br />
				return null;				<br />
			}<br />
		}<br />
	}<br />
}<br />
<br />
<br />


Class Student.cs

using System;<br />
using System.IO;<br />
using System.Runtime.Serialization;<br />
using System.Xml.Serialization;<br />
namespace WindowsApplication1<br />
{<br />
	/// <summary><br />
	/// Summary description for Student.<br />
	/// </summary><br />
	[Serializable]<br />
	public class Student<br />
	{<br />
		private int intStudentID = 0;<br />
		private string strName = "";<br />
		private string strAddress = "";<br />
<br />
		public Student(){}<br />
		public Student(int sID, string n, string a)<br />
		{<br />
			StudentID = sID;<br />
			Name = n;<br />
			Address = a;<br />
		}<br />
		public int StudentID<br />
		{<br />
			get{return intStudentID;}<br />
			set{intStudentID = value;}<br />
		}<br />
		public string Name<br />
		{<br />
			get{return strName;}<br />
			set{strName = value;}<br />
		}<br />
		public string Address<br />
		{<br />
			get{return strAddress;}<br />
			set{strAddress = value;}<br />
		}<br />
	}<br />
}<br />



The following is the code that I have used to attempt to serialize the class.

StreamWriter w = null;<br />
    try<br />
    {<br />
        XmlSerializer ser = new XmlSerializer(typeof(Students));<br />
        w =  new StreamWriter("class.xml");<br />
        ser.Serialize(w,  Hstudents);<br />
    } // try<br />
    catch (Exception ex)<br />
    {<br />
        string strErr = String.Format("Unable to serialize class, error '{0}'",<br />
            ex.Message);<br />
        MessageBox.Show(strErr,"Serialize Error",MessageBoxButtons.OK,<br />
            MessageBoxIcon.Error);<br />
    } // catch<br />
    finally<br />
    {<br />
        if (w != null) w.Close();<br />
        w = null;<br />
    } // finally



If i change it to work with binary serialization, the serialization works fine. Is there somethign special that i have to do to the classes to get it to serialize correctly?
GeneralRe: XML Serialization and ArrayLists Pin
Heath Stewart23-Mar-04 13:45
protectorHeath Stewart23-Mar-04 13:45 
GeneralWindows XP P2P SDK wrapped in .Net Pin
schnee2k323-Mar-04 13:03
schnee2k323-Mar-04 13:03 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
Heath Stewart23-Mar-04 13:34
protectorHeath Stewart23-Mar-04 13:34 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
schnee2k323-Mar-04 13:40
schnee2k323-Mar-04 13:40 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
Matthew Hazlett23-Mar-04 14:48
Matthew Hazlett23-Mar-04 14:48 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
leppie24-Mar-04 6:17
leppie24-Mar-04 6:17 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
schnee2k324-Mar-04 13:07
schnee2k324-Mar-04 13:07 
QuestionHow to change url of running iexplorer instance? Pin
ckl_8823-Mar-04 12:47
ckl_8823-Mar-04 12:47 
AnswerRe: How to change url of running iexplorer instance? Pin
Heath Stewart23-Mar-04 13:01
protectorHeath Stewart23-Mar-04 13:01 
GeneralRe: How to change url of running iexplorer instance? Pin
ckl_8823-Mar-04 13:50
ckl_8823-Mar-04 13:50 
GeneralRe: How to change url of running iexplorer instance? Pin
Heath Stewart23-Mar-04 14:01
protectorHeath Stewart23-Mar-04 14:01 
GeneralStrange problem with ownerdraw listbox Pin
Anders Molin23-Mar-04 12:41
professionalAnders Molin23-Mar-04 12:41 
GeneralRe: Strange problem with ownerdraw listbox Pin
Heath Stewart23-Mar-04 13:05
protectorHeath Stewart23-Mar-04 13:05 
GeneralRe: Strange problem with ownerdraw listbox Pin
Anders Molin23-Mar-04 13:22
professionalAnders Molin23-Mar-04 13:22 
GeneralRe: Strange problem with ownerdraw listbox Pin
Heath Stewart23-Mar-04 13:37
protectorHeath Stewart23-Mar-04 13:37 
GeneralRe: Strange problem with ownerdraw listbox Pin
Anders Molin23-Mar-04 13:40
professionalAnders Molin23-Mar-04 13:40 
GeneralRe: Strange problem with ownerdraw listbox Pin
Heath Stewart23-Mar-04 13:48
protectorHeath Stewart23-Mar-04 13:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.