(200-08-02) C#.NET 解構子

摘要:(200-07-30) C#.NET 解構子

建立 類別 並產生 解構子

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mod01
{
    public class Employee
    {
        public Employee() { }
        //解構子
        ~Employee()
        {
            //類別成員
            AppUtil.writeMsg(@"c:\mylog.txt","Employee解構了!!"+DateTime.Now.ToString());
        }
    }
}

 

主程式

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mod01
{
    class AppUtil
    {
        public static void writeMsg(String path, String msg)
        {
            //1.建立串流
            System.IO.FileStream fs1 = new System.IO.FileStream(path, System.IO.FileMode.Append, System.IO.FileAccess.Write);
            //2.寫出器
            System.IO.StreamWriter writer = new System.IO.StreamWriter(fs1);
            writer.WriteLine(msg);
            writer.Flush();
            writer.Close();
            fs1.Close();
        }
    }
}