C#中Dispose和Close的区别__教程 |
|
日期:2007-5-9 18:53:14 人气:228 [大 中 小] |
|
|
|
63 { 64 m_anotherImage.Dispose(); 65 } 66 67 Marshal.FreeCoTaskMem(m_anotherMemory); 68 base.Dispose(isDisposing); 69 m_disposed = true; 70 } 71 } 72 73 public static void Main(string[] args) 74 { 75 MyStream aStream = new MyDerivedStream(); 76 77 aStream.Close(); // Allowed 78 // aStream.Dispose(); // Cannot compile 79 80 ((IDisposable)aStream).Dispose(); // Allowed 81 82 // 83 // This one works as well, because newStream calls the explicit implemented 84 // IDisposable.Dispose method 85 // 86 using (MyStream newStream = new MyDerivedStream()) 87 { 88 // 89 // Do something 90 // 91 } 92 } 93 94 private IntPtr m_anotherMemory; 95 private Bitmap m_anotherImage; 96 private bool m_disposed; |
|
出处:本站原创 作者:佚名 |
|
|