Hi All,
I may be a little confused on indexers and properties. Is there any way to a have a parameterized property?
For instance, say a control I am creating has a number of labels on it. I would like to have properties called "LabelColor" and "Text" for this class, but would like to pass in an index to tell which label to update.
For instance, here is a simplified class:
Code:
public class MyClass
{
private ArrayList m_MyLabelList = new ArrayList();
|
public Color LabelColor
{
get
{
return (m_MyLabelList[SomeIndex].ForeColor);
}
set
{
m_MyLabelList[SomeIndex].ForeColor = value;
}
}
public string Text
{
get
{
return (m_MyLabelList[SomeIndex].Text);
}
set
{
m_MyLabelList[SomeIndex].Text = value;
}
}
}
and then from code that uses this class:
Code:
public MyClass test = new MyClass();
Color ThisColor = test[0].Color;
string ThisText = test[0].Text;
test[1].Color = Color.Green;
test[1].Text = "This is label #1";
test[2].Color = Color.DarkKhaki;
test[2].Text = "This is label #2";
Any hints or pointers to code examples would be most appreciated.
Thanks,
pagates