M
Martin Robins
Marc has sorted my problem with the collections, however I am now in a new scenario; I am trying to compare a generic property value before setting it as shown below ...
public T Value {
get { return this.value; }
set {
if ( this.value != value ) {
this.value = value;
this.OnValueChanged(EventArgs.Empty);
}
}
}
This code produces the Operator '==' cannot be applied to operands of type 'T' and 'T' error at compile time!
I am sure that I am not the only person to have tried this, any clues as to the correct work around?
I have tried restricting 'T' to IComparable in a where clause and then casting 'this.value' and 'value' to IComparable for the comparison - the code then compiles but is this the right answer? It feels wrong, but I am quickly learning that my own understanding of generics is much lower than I thought it was!
Thanks in advance.
public T Value {
get { return this.value; }
set {
if ( this.value != value ) {
this.value = value;
this.OnValueChanged(EventArgs.Empty);
}
}
}
This code produces the Operator '==' cannot be applied to operands of type 'T' and 'T' error at compile time!
I am sure that I am not the only person to have tried this, any clues as to the correct work around?
I have tried restricting 'T' to IComparable in a where clause and then casting 'this.value' and 'value' to IComparable for the comparison - the code then compiles but is this the right answer? It feels wrong, but I am quickly learning that my own understanding of generics is much lower than I thought it was!
Thanks in advance.