Hi All,
I've got a problem with the following example test code crashing,
complaining that the object reference is not set (.NET 1.1). Basically, I
instantiate a
collection of objects and begin populating the collection with appropriate
objects, then print them out. What am I doing wrong to cause the crash?
Seems like it should be obvious, but I'm not seeing it.
private void Form1_Load(object sender, System.EventArgs e)
{
MyObjCollection moc = new MyObjCollection();
MyObj mo1 = new MyObj("Object1");
moc.Add(mo1);
MyObj mo2 = new MyObj("Object2");
moc.Add(mo2);
foreach(MyObj obj in moc)
{
MessageBox.Show(obj.MyVar1);
}
}
internal sealed class MyObj
{
private string m_MyVar1 = "FooBar";
internal MyObj(string MyVar1)
{
m_MyVar1 = MyVar1;
}
internal string MyVar1
{
get
{
return m_MyVar1;
}
}
}
internal sealed class MyObjCollection : BaseCollection
{
internal MyObjCollection()
{
}
internal void Add(MyObj obj)
{
this.List.Add(obj);
}
}
Any help would be much appreciated. TIA,
--
John Bowman
Verona, WI
18*******@charter.net