Beispiel #1
0
        public static void ShowDispose()
        {
            ResourceHolderDerived resourceHolderDerived = new ResourceHolderDerived();
            ResourceHolderBase    resourceHolderBase    = new ResourceHolderBase();

            Console.WriteLine("Disposing derived:");
            resourceHolderDerived.Dispose();

            Console.WriteLine("\nDisposing base:");
            resourceHolderBase.Dispose();

            Console.WriteLine("\nDisposing derived one more time:");
            resourceHolderDerived.Dispose();
            Console.WriteLine("->No exception here\n");
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var baseHolder = new ResourceHolderBase();

            using (baseHolder)
            {
                baseHolder.BaseAction();
            }
            using (var derivedHolder = new ResourceHolderBase())
            {
                derivedHolder.BaseAction();
            }
            baseHolder.Dispose();

            Console.ReadLine();
        }