<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FClass_Interface%2FDestructor</id>
		<title>Csharp/C Sharp/Class Interface/Destructor - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FClass_Interface%2FDestructor"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Destructor&amp;action=history"/>
		<updated>2026-04-29T20:16:29Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Destructor&amp;diff=610&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Destructor&amp;diff=610&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Destructor&amp;diff=611&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Class_Interface/Destructor&amp;diff=611&amp;oldid=prev"/>
				<updated>2010-05-26T11:39:09Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Demonstrate a destructor==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C#: The Complete Reference &lt;br /&gt;
by Herbert Schildt &lt;br /&gt;
Publisher: Osborne/McGraw-Hill (March 8, 2002)&lt;br /&gt;
ISBN: 0072134852&lt;br /&gt;
*/&lt;br /&gt;
// Demonstrate a destructor. &lt;br /&gt;
 &lt;br /&gt;
using System; &lt;br /&gt;
 &lt;br /&gt;
class Destruct {  &lt;br /&gt;
  public int x;  &lt;br /&gt;
  &lt;br /&gt;
  public Destruct(int i) {  &lt;br /&gt;
    x = i;  &lt;br /&gt;
  }    &lt;br /&gt;
 &lt;br /&gt;
  // called when object is recycled &lt;br /&gt;
  ~Destruct() { &lt;br /&gt;
    Console.WriteLine(&amp;quot;Destructing &amp;quot; + x); &lt;br /&gt;
  } &lt;br /&gt;
   &lt;br /&gt;
  // generates an object that is immediately destroyed &lt;br /&gt;
  public void generator(int i) { &lt;br /&gt;
    Destruct o = new Destruct(i); &lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
}    &lt;br /&gt;
    &lt;br /&gt;
public class DestructDemo1 {    &lt;br /&gt;
  public static void Main() {    &lt;br /&gt;
    int count; &lt;br /&gt;
 &lt;br /&gt;
    Destruct ob = new Destruct(0); &lt;br /&gt;
 &lt;br /&gt;
    /* Now, generate a large number of objects.  At &lt;br /&gt;
       some point, garbage collection will occur.  &lt;br /&gt;
       Note: you might need to increase the number &lt;br /&gt;
       of objects generated in order to force &lt;br /&gt;
       garbage collection. */ &lt;br /&gt;
 &lt;br /&gt;
    for(count=1; count &amp;lt; 100000; count++) &lt;br /&gt;
      ob.generator(count);  &lt;br /&gt;
 &lt;br /&gt;
    Console.WriteLine(&amp;quot;Done&amp;quot;); &lt;br /&gt;
  }    &lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Finalizable Disposable Class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
class Program {&lt;br /&gt;
    static void Main(string[] args) {&lt;br /&gt;
        using (MyResourceWrapper rw = new MyResourceWrapper()) {&lt;br /&gt;
        }&lt;br /&gt;
        MyResourceWrapper rw2 = new MyResourceWrapper();&lt;br /&gt;
        for (int i = 0; i &amp;lt; 10; i++)&lt;br /&gt;
            rw2.Dispose();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class MyResourceWrapper : IDisposable {&lt;br /&gt;
    public void Dispose() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;In Dispose() method!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==force the GC to invoke Finalize() for finalizable objects created in this AppDomain.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MyResourceWrapper {&lt;br /&gt;
    ~MyResourceWrapper() {&lt;br /&gt;
        Console.Beep();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Program {&lt;br /&gt;
    static void Main(string[] args) {&lt;br /&gt;
        MyResourceWrapper rw = new MyResourceWrapper();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Illustrates a destructor==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example5_14.cs illustrates a destructor&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
// declare the Car class&lt;br /&gt;
class Car&lt;br /&gt;
{&lt;br /&gt;
  // define the destructor&lt;br /&gt;
  ~Car()&lt;br /&gt;
  {&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;In ~Car() destructor&amp;quot;);&lt;br /&gt;
    // do any cleaning up here&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Example5_14&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    // create a Car object&lt;br /&gt;
    Car myCar = new Car();&lt;br /&gt;
    System.Console.WriteLine(&amp;quot;At the end of Main()&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Shows that stack unwinding in C# does not necessarily call destructors==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
C# Programming Tips &amp;amp; Techniques&lt;br /&gt;
by Charles Wright, Kris Jamsa&lt;br /&gt;
Publisher: Osborne/McGraw-Hill (December 28, 2001)&lt;br /&gt;
ISBN: 0072193794&lt;br /&gt;
*/&lt;br /&gt;
// Unwind.cs -- Shows that stack unwinding in C# does not necessarily call&lt;br /&gt;
//              destructors.&lt;br /&gt;
//              Compile this program with the following command line:&lt;br /&gt;
//                  C:&amp;gt;csc Unwind.cs&lt;br /&gt;
//&lt;br /&gt;
namespace nsStack&lt;br /&gt;
{&lt;br /&gt;
    using System;&lt;br /&gt;
    using System.IO;&lt;br /&gt;
    &lt;br /&gt;
    public class Unwind&lt;br /&gt;
    {&lt;br /&gt;
        static public void Main ()&lt;br /&gt;
        {&lt;br /&gt;
            Unwind main = new Unwind();&lt;br /&gt;
            // Set up the try ... catch block&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                main.TestStack ();&lt;br /&gt;
            }&lt;br /&gt;
            catch (FileNotFoundException e)&lt;br /&gt;
            {&lt;br /&gt;
                // Show the contents of the Message string in each class object&lt;br /&gt;
                if (clsFirst.Message == null)&lt;br /&gt;
                     Console.WriteLine (&amp;quot;First message is null&amp;quot;);&lt;br /&gt;
                else&lt;br /&gt;
                     Console.WriteLine (clsFirst.Message);&lt;br /&gt;
                if (clsFirst.Message == null)&lt;br /&gt;
                     Console.WriteLine (&amp;quot;Second message is null&amp;quot;);&lt;br /&gt;
                else&lt;br /&gt;
                     Console.WriteLine (clsSecond.Message);&lt;br /&gt;
                if (clsFirst.Message == null)&lt;br /&gt;
                     Console.WriteLine (&amp;quot;Third message is null&amp;quot;);&lt;br /&gt;
                else&lt;br /&gt;
                     Console.WriteLine (clsThird.Message);&lt;br /&gt;
                // Show the exception object message&lt;br /&gt;
                Console.WriteLine (e.Message);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
        void TestStack ()&lt;br /&gt;
        {&lt;br /&gt;
            // Create a new clsFirst object and call a method in it&lt;br /&gt;
            clsFirst first = new clsFirst ();&lt;br /&gt;
            first.FirstFunc();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    class clsFirst&lt;br /&gt;
    {&lt;br /&gt;
        ~clsFirst ()&lt;br /&gt;
        {&lt;br /&gt;
            Message = &amp;quot;clsFirst destructor called&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
        static public string Message = null;&lt;br /&gt;
        public void FirstFunc()&lt;br /&gt;
        {&lt;br /&gt;
            // Create a new clsSecond object and call a method in it&lt;br /&gt;
            clsSecond second = new clsSecond();&lt;br /&gt;
            second.SecondFunc ();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    class clsSecond {&lt;br /&gt;
        ~clsSecond () {&lt;br /&gt;
            Message = &amp;quot;clsSecond destructor called&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
        static public string Message = null;&lt;br /&gt;
        public void SecondFunc()&lt;br /&gt;
        {&lt;br /&gt;
            // Create a new clsThird object and call a method in it&lt;br /&gt;
            clsThird third = new clsThird();&lt;br /&gt;
            third.ThirdFunc ();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    class clsThird&lt;br /&gt;
    {&lt;br /&gt;
        ~clsThird () {&lt;br /&gt;
            Message = &amp;quot;clsThird destructor called&amp;quot;;&lt;br /&gt;
        }&lt;br /&gt;
        static public string Message = null;&lt;br /&gt;
        public void ThirdFunc() {&lt;br /&gt;
            ThrowException ();&lt;br /&gt;
        }&lt;br /&gt;
        // By the time the program gets here, it is five method calls deep.&lt;br /&gt;
        // Throw an exception to force a stack unwind.&lt;br /&gt;
        private void ThrowException () {&lt;br /&gt;
            throw (new FileNotFoundException ());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==the destructors are called bottom-up, which confirms the sequencing of destructors.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
public class Starter {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        XClass obj = new XClass();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class MyClass {&lt;br /&gt;
    ~MyClass() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;MyClass destructor&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class YClass : MyClass {&lt;br /&gt;
    ~YClass() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;YClass destructor&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class XClass : YClass {&lt;br /&gt;
    ~XClass() {&lt;br /&gt;
        Console.WriteLine(&amp;quot;XClass destructor&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>