the answer I was looking for. I particularly liked the IEqualityComparer
"Martin Robins" <martin at orpheus-solutions dot co dot uk> wrote in message
news:OrggXiylIHA.3636@TK2MSFTNGP02.phx.gbl...
> Barry,
>
> Thanks; that seems to have done the trick (in as much as it is providing
> the correct results).
>
> Martin.
>
> "Barry Kelly" <barry.j.kelly@gmail.com> wrote in message
> news:8ujdv35e4jl1jmbprf6kkppc2dg9vdpc1m@4ax.com...
>> "Martin Robins" <martin at orpheus-solutions dot co dot uk> wrote:
>>
>>> 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?
>>
>> The normal pattern for comparing values of a generic type is to use
>> Comparer<T>.Default (if you need ordering) or
>> EqualityComparer<T>.Default (if you need equality and hashing).
>>
>> EqualityComparer<T>.Default delegates to an IEquatable<T> interface if
>> it exists, or fall back to the Object.Equals override, if any.
>>
>> Then, if you deal with some T where you want to customize behaviour
>> (strings come to mind - do you want case-sensitive versus insensitive
>> behaviour?), you create an overloaded constructor which takes an
>> IEqualityComparer<T> instance, and pass EqualityComparer<T>.Default in
>> the other overload. All comparisons should be done through the cached
>> interface value.
>>
>> For the concrete case of strings, you can then use
>> StringComparer.Ordinal, StringComparer.InvariantCultureIgnoreCase, as
>> the argument etc.
>>
>> -- Barry
>>
>> --
>>
http://barrkel.blogspot.com/ >
>