C
Chuck P
I have a DisplayValueItem object that is used to fill a ComboListBox
with items. It used to be the Value and Display members were string.
I changed it to a generic (T, string) and now the below code fails.
x = new DisplayValueItem < int >(1, "stuff");
clbOutcomes.Items.Add(x);
bFound = clbOutcomes.Items.Contains(x);
bFound = clbOutcomes.Items.Contains(new DisplayValueItem < int >(1,
"stuff"));
bFound for x comes out true
bFound for new comes out false
I don't understand why it worked before I turned the DisplayValueItem
from a non-Generic (string, string) into a Generic (T,string).
public class DisplayValueItem
{
private string mValue;
private string mDisplay;
public DisplayValueItem(string ValueField, string
DisplayField)
{
mValue = ValueField;
mDisplay = DisplayField;
}
public string Value
{
get { return mValue; }
}
public string Display
{
get { return mDisplay; }
}
}
public class DisplayValueItem<T>
{
private T mValue;
private string mDisplay;
public DisplayValueItem(T ValueField, string DisplayField)
{
mValue = ValueField;
mDisplay = DisplayField;
}
public T Value
{
get { return mValue; }
}
public string Display
{
get { return mDisplay; }
}
}
with items. It used to be the Value and Display members were string.
I changed it to a generic (T, string) and now the below code fails.
x = new DisplayValueItem < int >(1, "stuff");
clbOutcomes.Items.Add(x);
bFound = clbOutcomes.Items.Contains(x);
bFound = clbOutcomes.Items.Contains(new DisplayValueItem < int >(1,
"stuff"));
bFound for x comes out true
bFound for new comes out false
I don't understand why it worked before I turned the DisplayValueItem
from a non-Generic (string, string) into a Generic (T,string).
public class DisplayValueItem
{
private string mValue;
private string mDisplay;
public DisplayValueItem(string ValueField, string
DisplayField)
{
mValue = ValueField;
mDisplay = DisplayField;
}
public string Value
{
get { return mValue; }
}
public string Display
{
get { return mDisplay; }
}
}
public class DisplayValueItem<T>
{
private T mValue;
private string mDisplay;
public DisplayValueItem(T ValueField, string DisplayField)
{
mValue = ValueField;
mDisplay = DisplayField;
}
public T Value
{
get { return mValue; }
}
public string Display
{
get { return mDisplay; }
}
}