• Source
    1. using System;
    2. public class Person: IDisposable
    3. {
    4. public int Id { get; set; }
    5. public string FullName { get; set; }
    6. public int Age { get; set; }
    7.  
    8. public Person()
    9. {
    10.  
    11. }
    12.  
    13. public Person(int id, string fullName, int age)
    14. {
    15. Id = id;
    16. FullName = fullName;
    17. Age = age;
    18. }
    19.  
    20. /// <summary>
    21. /// Implement interface
    22. /// </summary>
    23. public void Dispose()
    24. {
    25. //Do somethings here . . .
    26. Console.WriteLine("\n Hi boys, This is a final message to you !");
    27. }
    28. }
    29. public class Test
    30. {
    31. public static void Main()
    32. {
    33. using(Person p = new Person(1, "BravoHex", 25),
    34. p1 =new Person(),
    35. p2 = new Person(3,"Tuan Le Minh",27))
    36. {
    37. Console.WriteLine(" Name: {0} \n Age: {1}", p.FullName, p.Age);
    38. }
    39. Console.ReadKey();
    40. }
    41. }