TQC+ C# 認證教學手冊

310、物件生命週期

檔案:Program.cs

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

namespace CSD03
{
    class Program
    {
        static void Main(string[] args)
        {
            using (TaiwanBigLottory lottory = new TaiwanBigLottory())
            {
                for (int i = 0; i < 10; i++)
                {
                    List<int> nums = lottory.GetLottorySequence().ToList();
                    for (int j = 0; j < nums.Count() - 1; j++)
                    {
                        Console.Write("{0:00} ", nums[j]);
                    }

                    Console.WriteLine("S:{0:00}", nums.Last());
                }
            }

            Console.ReadLine();
        }
    }
}

檔案:LottoryBase.cs

namespace CSD03
{
    public abstract class LottoryBase : IDisposable
    {

        // skip ...

        void IDisposable.Dispose()
        {
            this._lottoryNumberContext.Clear();
            this._lottoryNumberContext = null;
            GC.SuppressFinalize(this);
        }
    }
}