Hi Guys
NP120 understanding instance
FileStream fs = new FileStream ("aFile.txt", FileMode.Create, FileAccess.ReadWrite,FileShare.None);
StreamWriter sw = new StreamWriter(fs);
I have had a problem in understanding the above one. I wish to know whether it is correct to say instance of a StreamWriter which is sw is equal to instance of a FileStream which is fs. That means sw = fs.
Please help me.
Thank you
Posted Aug 12, 2008, 7:20 AM
Thank you for your explanation.
AlanPosted Aug 12, 2008, 5:56 AM
No, it's not correct to say that an instance of a StreamWriter is equal to an instance of a FileStream, because they are different (and unrelated) classes.
When you execute this line:
StreamWriter sw = new StreamWriter(fs);
you are constructing an instance of StreamWriter and associating it with a FileStream object to write to. In other words, StreamWriter writes to streams, it is not a stream itself.