Articles → CSHARP → Using Keyword For Custom Class In C#
Using Keyword For Custom Class In C#
Public class Employee {
public Employee() {
MyDataSet = new DataSet();
}
public DataSet MyDataSet {
get;
set;
}
}
using(Employee emp = new Employee()) {
}
public class Employee: IDisposable {
public Employee() {
MyDataSet = new DataSet();
}
public DataSet MyDataSet {
get;
set;
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
private bool IsDisposed = false;
protected virtual void Dispose(bool disposing) {
if (!IsDisposed && disposing) {
MyDataSet.Dispose();
IsDisposed = true;
}
}
}