Re: compare a list of integers
- From: Marc Gravell <marc.gravell@xxxxxxxxx>
- Date: Sun, 27 Apr 2008 03:31:38 -0700 (PDT)
but I thought extension methods would make things slow? been trying to avoid
them
Why would you think that? OK, in reality you could shave a few cycles
if you know you have List<T> by checking the length first
(SequenceEqual doesn't do this, although this could be a missed
opportunity - it could check if both operands implement IList, and
compare the length) - and because it is using the interface (rather
than direct to the sealed List<T>) it won't inline any of the fetches
- but this is rarely the most significant thing.
My advice: use the simplest code that clearly expresses what you want
to do. SequenceEqual does this; *if* you later find this is a
bottleneck, then tweak it (perhaps introduce a List<T> SequenceEqual
extension method) - but until then you're optimising prematurely.
Marc
.
- Follow-Ups:
- Re: compare a list of integers
- From: Marc Gravell
- Re: compare a list of integers
- References:
- compare a list of integers
- From: Tem
- Re: compare a list of integers
- From: Jon Skeet [C# MVP]
- Re: compare a list of integers
- From: Tem
- compare a list of integers
- Prev by Date: C# and UNIX Compatibility Issues?
- Next by Date: Re: compare a list of integers
- Previous by thread: Re: compare a list of integers
- Next by thread: Re: compare a list of integers
- Index(es):
Relevant Pages
|