Hi,
I've created a class called MyClass which just contains some data:
public class MyClass
{
#region Private Variables
private string _ValueA;
private string _ValueB;
#endregion
public MyClass(string ValueA, string ValueB)
{
_ValueA= ValueA;
_ValueB= ValueB;
}
public string ValueA
{
get { return _ValueA; }
set { _ValueA= value; }
}
public string ValueB
{
get { return _ValueB; }
set { _ValueB= value; }
}
}
In my code i've got some data and made an ArrayList of MyClass containing the data. That all seems to work fine.
In the next bit of code I want to go through the ArrayList, but I'm having trouble getting anything from it.
ArrayList TestArrayList = GetData();
for (int i = 0; i < TestArrayList .Count; i++) <---- this count is 14
{
MyClass anElement = (MyClass)TestArrayList [i]; <--- is null here all the time
}
If I do the following and debug it, I get a Count of 14, but each returned element is null. Yet, when I break and watch the TestArrayList I can see each element is there, it's just when I MyClass anElement = (MyClass)TestArrayList ; it seems to return null.
I'm only doing it like this because when I tried to use List<MyClass> in GetData() I get an exception saying the object is not of MyClass type and I can not add it.
So, Questions:
1) Why can't I see what is in the ArrayList?
2) Less importantly, is there any commonly known reason why I couldn't add this class to a List<MyClass>?
Please ask any questions which will help as i'm not really sure what else I can say (otherwise I would have solved this myself ;) )
Many thanks in advance,
Phil