I always find very sophisticated way to serialize all kind of objects, lists and who knows, But I can't seem to find a simple way to serialize an array.
(I found one, but its serializing the array to a binary file, and I need to be able to edit the serialized file in any regular text editor [It's a language file, I need to give copies to my co-workers so they can translate the file into other languages/])
Assuming your array is an array of strings...
using (var stream = File.Create("file.xml")) {
var serializer = new XmlSerializer(typeof(string[]));
serializer.Serialize(stream, someArrayOfStrings);
}
Will create a simple XML file that is very easy to understand/modify. To deserialize it, use the Deserialize method.
Human readable? I'd go for JavaScriptSerializer; just:
string json = new JavaScriptSerializer().Serialize(arr);
It's a language file, I need to give copies to my co-workers so they can translate the file into other language
XML Serialization is ideal it sounds like based on the above statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With