Esempio n. 1
0
        static void Main(string[] args)
        {
            TxtRepo repo = new TxtRepo();

            try
            {
                Console.WriteLine(repo.GetTextFromFile("Files/TextFile.txt"));
            }
            catch (Exception ex)
            {
                //log()
            }
            finally //finally wykonuje sie zawsze
            {
                repo.Dispose();
            }

            using (TxtRepo repo2 = new TxtRepo())
            {
                Console.WriteLine("In using");
                Console.WriteLine(repo2.GetTextFromFile("Files/TextFile.txt"));
            }

            Console.Read();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            TxtRepo repo = new TxtRepo();

            try
            {
                Console.WriteLine(repo.GetTextFromFile("Files/TextFile.txt"));
            }
            finally
            {
                repo.Dispose();     // zniszczenie obiektu
            }

            // lub (to samo)
            using (TxtRepo repo2 = new TxtRepo())
            {
                Console.WriteLine("In using");
                Console.WriteLine(repo2.GetTextFromFile("Files/TextFile.txt"));
            }

            Console.Read();
        }