Thursday, 13 November 2008

StreamReaders, StringWriters, MemoryStreams, FileStreams, Serialization in .NET

StreamReader - read files as lines of strings
FileStream - read files as arrays of bytes (need an Encoding to tranlsate back to strings)
MemoryStream - reads data from memory instead of from file

System.Runtime.Serialization
System.Xml.Serialization

Example of serialization of List:

TextWriter writer = new StreamWriter(PATH);
XmlSerializer serializer = new XmlSerializer(typeof(List<long>)) -- typeof returns an object of type Type
serializer.Serialize(writer, mylist);
writer.Close();

StringWriter - stream that can morph into a string
Path.GetTempFileName - create temp file and return full path

No comments: