Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Custom Component : Dispose Method (http://www.velocityreviews.com/forums/t774939-custom-component-dispose-method.html)

pete 12-03-2004 04:57 PM

Custom Component : Dispose Method
 
Hi Guys,

Apologies for the long post.

I'm following a tutorial on developing components and am having trouble
understanding some of the code. Its a simple RandomNumber component and
although I've removed the comments (to save space) its pretty easy to
follow.

The parts I don't understand are as follows:

1) Visual Studio add a System.ComponentModel.Container variable named
components. Can you tell me what this is for?
2) The tutorial I'm following says I should override the Diposing(bool)
method. Despite providing the code it doesn't explain why I need to do this
or explain exactly what is going on in the code. Can you explain this to me?

Cheers, Pete


using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;

namespace HelperClasses
{
public class RandomNumber : System.ComponentModel.Component
{
private int _minValue;
private int _maxValue;

private System.ComponentModel.Container components = null;

public int MinValue
{
get
{
return _minValue;
}
set
{
_minValue = value;
}
}

public int MaxValue
{
get
{
return _maxValue;
}
set
{
_maxValue = value;
}
}

public RandomNumber(System.ComponentModel.IContainer container)
{
container.Add(this);
InitializeComponent();
}

public RandomNumber()
{
InitializeComponent();

MinValue=0;
MaxValue=100;
}

private void InitializeComponent()
{

}
#endregion


protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);

_minValue = 0;
_maxValue = 0;
}


public int GenerateRandomNumber()
{
Random r = new Random();
return r.Next(MinValue, MaxValue);

}
}
}




All times are GMT. The time now is 12:44 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.