-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestructors.cs
More file actions
58 lines (52 loc) · 1.36 KB
/
Destructors.cs
File metadata and controls
58 lines (52 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpProgramming
{
public class Trainees:IDisposable
{
public Trainees()
{
Console.WriteLine("Default Constructor");
}
/// <summary>
/// Dispose method implemented from IDisposable interface
/// </summary>
public void Dispose()
{
Console.WriteLine("Resources are set free");
}
/// <summary>
/// Destructors- deallocate the memory
/// one destructor
/// prefixed with ~tilde symbol
/// no return type nor access specifiers
/// Garbage Collection - free the memory
/// Finalize() and Dispose() - files,database connection,service or any third party resources
/// </summary>
~Trainees()
{
Console.WriteLine("Destructor Called");
}
//protected override void Finalize()
//{
// try
// {
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.ToString());
// }
//}
}
internal class Destructors
{
public static void Main()
{
Trainees trainees=new Trainees();
trainees.Dispose();
}
}
}