Why must I Close() a file in C#?

后端 未结 6 1520
自闭症患者
自闭症患者 2021-02-20 12:47

I know this might seem silly, but why does the following code only work if I Close() the file? If I don\'t close the file, the entire stream is not written.

Steps:

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-20 13:13

    Because the C# designers were cloning Java and not C++ despite the name.

    In my opinion they really missed the boat. C++ style destruction on scope exit would have been so much better.

    It wouldn't even have to release the memory to be better, just automatically run the finalizer or the IDisposable method.

提交回复
热议问题