using System; using System.IO; 1. namespace Finalizers 2. { 3. internal class FileGenerator : IDisposable 4. { 5. public FileGenerator() 6. { 7. } 8. ~FileGenerator() 9. { 10. // Just a debug output 11. Console.WriteLine("Closing file!"); 12. } 13. public void Generate(int Length) 14. { 15. // Here some work is done... 16. } 17. public void Dispose() 18. { 19. // Just a debug output 20. Console.WriteLine("Disposing object!"); 21. } 22. } 23. 24. class Program 25. { 26. static void Generate() 27. { 28. // Here it would be better to use the C# "using" keyword instead of implicitly calling Dispose! 29. using (var fGen = new FileGenerator()) 30. { 31. fGen.Generate(512); 32. //fGen.Dispose(); 33. } 34. } 35. static void Main(string[] args) 36. { 37. Generate(); 38. // Here we do some work; simulated by ReadLine statement 39. Console.Write("Please Press Enter..."); 40. Console.ReadLine(); 41. } 42. } 43. }
using
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)