Click here to Skip to main content
15,923,789 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trig: Calculating points on a line Pin
J4amieC21-Aug-05 9:53
J4amieC21-Aug-05 9:53 
GeneralSave inside a file ArrayList code Pin
Sasuko17-Aug-05 11:18
Sasuko17-Aug-05 11:18 
GeneralRe: Save inside a file ArrayList code Pin
Guffa17-Aug-05 12:07
Guffa17-Aug-05 12:07 
GeneralRe: Save inside a file ArrayList code Pin
Sasuko17-Aug-05 12:16
Sasuko17-Aug-05 12:16 
GeneralRe: Save inside a file ArrayList code Pin
Guffa17-Aug-05 21:07
Guffa17-Aug-05 21:07 
GeneralRe: Save inside a file ArrayList code Pin
S. Senthil Kumar17-Aug-05 21:00
S. Senthil Kumar17-Aug-05 21:00 
GeneralRe: Save inside a file ArrayList code Pin
Sasuko17-Aug-05 21:49
Sasuko17-Aug-05 21:49 
GeneralRe: Save inside a file ArrayList code Pin
Azerax20-Aug-05 2:22
Azerax20-Aug-05 2:22 
Check out these two functions for serializing and deserializing data using a BinaryFormatter. It serializes a hashtable but can be replaced by an arraylist and should work just fine.



static void Serialize() <br />
		{<br />
			// Create a hashtable of values that will eventually be serialized.<br />
			Hashtable addresses = new Hashtable();<br />
			addresses.Add("Jeff", "123 Main Street, Redmond, WA 98052");<br />
			addresses.Add("Fred", "987 Pine Road, Phila., PA 19116");<br />
			addresses.Add("Mary", "PO Box 112233, Palo Alto, CA 94301");<br />
<br />
			// To serialize the hashtable and its key/value pairs,  <br />
			// you must first open a stream for writing. <br />
			// In this case, use a file stream.<br />
			FileStream fs = new FileStream("DataFile.dat", FileMode.Create);<br />
<br />
			// Construct a BinaryFormatter and use it to serialize the data to the stream.<br />
			BinaryFormatter formatter = new BinaryFormatter();<br />
			try <br />
			{<br />
				formatter.Serialize(fs, addresses);<br />
			}<br />
			catch (SerializationException e) <br />
			{<br />
				Console.WriteLine("Failed to serialize. Reason: " + e.Message);<br />
				throw;<br />
			}<br />
			finally <br />
			{<br />
				fs.Close();<br />
			}<br />
		}<br />
<br />
   <br />
		static void Deserialize() <br />
		{<br />
			// Declare the hashtable reference.<br />
			Hashtable addresses  = null;<br />
<br />
			// Open the file containing the data that you want to deserialize.<br />
			FileStream fs = new FileStream("DataFile.dat", FileMode.Open);<br />
			try <br />
			{<br />
				BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
				// Deserialize the hashtable from the file and <br />
				// assign the reference to the local variable.<br />
				addresses = (Hashtable) formatter.Deserialize(fs);<br />
			}<br />
			catch (SerializationException e) <br />
			{<br />
				Console.WriteLine("Failed to deserialize. Reason: " + e.Message);<br />
				throw;<br />
			}<br />
			finally <br />
			{<br />
				fs.Close();<br />
			}<br />
<br />
			// To prove that the table deserialized correctly, <br />
			// display the key/value pairs.<br />
			foreach (DictionaryEntry de in addresses) <br />
			{<br />
				Console.WriteLine("{0} lives at {1}.", de.Key, de.Value);<br />
			}<br />
		}



Elvis (a.k.a Azerax)

Life is Music listen to it before it fades
GeneralMask the TextBox Pin
zaboboa17-Aug-05 10:11
zaboboa17-Aug-05 10:11 
GeneralRe: Mask the TextBox Pin
BammBamm17-Aug-05 10:59
BammBamm17-Aug-05 10:59 
GeneralRe: Mask the TextBox Pin
Mohamad Al Husseiny17-Aug-05 11:44
Mohamad Al Husseiny17-Aug-05 11:44 
GeneralRe: Mask the TextBox Pin
zaboboa18-Aug-05 2:22
zaboboa18-Aug-05 2:22 
GeneralRe: Mask the TextBox Pin
Mohamad Al Husseiny18-Aug-05 3:20
Mohamad Al Husseiny18-Aug-05 3:20 
GeneralRe: Mask the TextBox Pin
zaboboa18-Aug-05 3:36
zaboboa18-Aug-05 3:36 
GeneralRe: Mask the TextBox Pin
Mohamad Al Husseiny18-Aug-05 3:44
Mohamad Al Husseiny18-Aug-05 3:44 
GeneralNNTP sever Pin
Mridang Agarwalla17-Aug-05 9:12
Mridang Agarwalla17-Aug-05 9:12 
GeneralRe: NNTP sever Pin
leppie17-Aug-05 23:40
leppie17-Aug-05 23:40 
Generalremoving XML entries Pin
Mridang Agarwalla17-Aug-05 8:44
Mridang Agarwalla17-Aug-05 8:44 
GeneralRe: removing XML entries Pin
BammBamm17-Aug-05 8:53
BammBamm17-Aug-05 8:53 
GeneralRe: removing XML entries Pin
Mridang Agarwalla17-Aug-05 8:57
Mridang Agarwalla17-Aug-05 8:57 
GeneralRe: removing XML entries Pin
Mridang Agarwalla17-Aug-05 9:00
Mridang Agarwalla17-Aug-05 9:00 
GeneralRe: removing XML entries Pin
Mridang Agarwalla17-Aug-05 9:02
Mridang Agarwalla17-Aug-05 9:02 
GeneralRe: removing XML entries Pin
DavidNohejl17-Aug-05 9:06
DavidNohejl17-Aug-05 9:06 
GeneralRe: removing XML entries Pin
Mridang Agarwalla17-Aug-05 9:10
Mridang Agarwalla17-Aug-05 9:10 
GeneralRe: removing XML entries Pin
BammBamm17-Aug-05 9:22
BammBamm17-Aug-05 9:22 

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.