Be careful with the equals() and == they are not always the same code. 
Value types they will be classes or object they won't

Davy

-----Original Message-----
From: David Burstin <david.burs...@gmail.com>
Sender: ozdotnet-boun...@ozdotnet.com
Date: Wed, 28 Jul 2010 13:33:13 
To: ozDotNet<ozdotnet@ozdotnet.com>
Reply-To: ozDotNet <ozdotnet@ozdotnet.com>
Subject: Re: Generics, operators and native data types

Thanks guys.

On Wed, Jul 28, 2010 at 12:54 PM, Michael Minutillo <
michael.minuti...@gmail.com> wrote:

> This works. You might want to ensure that exclude is not null first:
>
> public static T[] Remaining<T>(this T[] list, T exclude) where T :
> IEquatable<T>
> {
>   return list.Where(x => exclude.Equals(x) == false).ToArray()
> }
>
>
>
> Michael M. Minutillo
> Indiscriminate Information Sponge
> Blog: http://wolfbyte-net.blogspot.com
>
>
>
> On Wed, Jul 28, 2010 at 10:42 AM, James Chapman-Smith <
> ja...@enigmativity.com> wrote:
>
>>  public static T[] Remaining<T>(this T[] list, T exclude)
>>
>> {
>>
>>    return list.Except(new T[] { exclude }).ToArray();
>>
>> }
>>
>>
>>
>>
>>
>> *From:* ozdotnet-boun...@ozdotnet.com [mailto:
>> ozdotnet-boun...@ozdotnet.com] *On Behalf Of *David Burstin
>> *Sent:* Wednesday, 28 July 2010 12:09
>> *To:* ozDotNet
>> *Subject:* Generics, operators and native data types
>>
>>
>>
>> Hi all,
>>
>>
>>
>> public static T[] Remaining<T>(this T[] list, T exclude)
>>
>> {
>>
>>  return list.Where(s => s != exclude).ToArray();
>>
>>  }
>>
>>
>>
>> gives me a "Cannot apply operator '!=' to operands of type T and T".
>>
>>
>>
>> Basically, I want to pass in an array and have it return an array without
>> the element [exclude]. The array can be strings, chars or ints.
>>
>>
>>
>> Any suggestions?
>>
>>
>>
>> Cheers
>>
>> Dave
>>
>
>

Reply via email to