If your objects in the arraylist are serializable, you can choose binary serialization. But this means that any other application needs to know serialization, and then only use these files. You can clarify the intention to use serialization. So the question remains: why do you need to serialize? If it's simple, for you (this app), you might consider binary serialization. Make sure your objects are serializable. Otherwise, you need to think about XML serialization.
For binary serialization, you can come up with the following code:
Stream stream = File.Open("C:\\mySerializedData.Net", FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, myArray);
stream.Close();
source
share