T
Tony Johansson
Hi!
I'm reading a book from Microsoft Press(MCTS). It says
*If you just needed to store a single string in a file, you wouldn't need to
use serialization
you could simply write the string directly to a text file. Serialization
becomes useful when storing more complex
information, such as the current date and time. As the following code sample
demonstates, serializing complex objects is as simple as serializing a
string."
Can anybode tell me the reason why to use serialization when I want to store
current date and time as the text above claims
when it's even simpler to store it directly in a file like I have done below
in example 2 here ?
Example 1
FileStream fs = new FileStream("Test1.data", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.serialize(fs,System.DateTime.Now);
fs.Close();
Example 2
StreamWriter sw = new StreamWriter("Test2.data");
sw.WriteLine(System.DateTime.Now.ToString());
sw.Close();
//Tony
I'm reading a book from Microsoft Press(MCTS). It says
*If you just needed to store a single string in a file, you wouldn't need to
use serialization
you could simply write the string directly to a text file. Serialization
becomes useful when storing more complex
information, such as the current date and time. As the following code sample
demonstates, serializing complex objects is as simple as serializing a
string."
Can anybode tell me the reason why to use serialization when I want to store
current date and time as the text above claims
when it's even simpler to store it directly in a file like I have done below
in example 2 here ?
Example 1
FileStream fs = new FileStream("Test1.data", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.serialize(fs,System.DateTime.Now);
fs.Close();
Example 2
StreamWriter sw = new StreamWriter("Test2.data");
sw.WriteLine(System.DateTime.Now.ToString());
sw.Close();
//Tony