T
Tony Johansson
Hi!
Here I have a class named Team and this class implement the IDisposable
interface.
I just wonder is any point using the Dispose method on the data that I do
here.
The Dispose method is included at the end of the code.
[CLSCompliant(true)]
public class Team : IDisposable
{
private ArrayList teamList;
private int teamSize;
private bool disposedValue = false;
public int TeamSize
{
get { return teamSize; }
set
{
if (value <= 0)
throw new Exception("Invalid teamSize <" + value + ">Usage
teamSize > 0");
teamSize = value;
}
}
public Team(int teamCapacity)
{
teamList = new ArrayList(teamCapacity);
teamSize = teamCapacity;
}
public void Add(Player player)
{
try
{
if (teamSize > teamList.Count)
teamList.Add(player);
else
throw new TeamListFilledException("Team roster is full <" +
TeamSize + "> - Cannot add more Players");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public ArrayList Players
{
get { return teamList; }
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!disposedValue)
{
if (disposing)
{
teamList.Clear();
teamList = null;
}
disposedValue = true;
}
}
}
Here I have a class named Team and this class implement the IDisposable
interface.
I just wonder is any point using the Dispose method on the data that I do
here.
The Dispose method is included at the end of the code.
[CLSCompliant(true)]
public class Team : IDisposable
{
private ArrayList teamList;
private int teamSize;
private bool disposedValue = false;
public int TeamSize
{
get { return teamSize; }
set
{
if (value <= 0)
throw new Exception("Invalid teamSize <" + value + ">Usage
teamSize > 0");
teamSize = value;
}
}
public Team(int teamCapacity)
{
teamList = new ArrayList(teamCapacity);
teamSize = teamCapacity;
}
public void Add(Player player)
{
try
{
if (teamSize > teamList.Count)
teamList.Add(player);
else
throw new TeamListFilledException("Team roster is full <" +
TeamSize + "> - Cannot add more Players");
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public ArrayList Players
{
get { return teamList; }
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
private void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!disposedValue)
{
if (disposing)
{
teamList.Clear();
teamList = null;
}
disposedValue = true;
}
}
}