|
![](/i/fill.gif) |
On 05/12/2012 02:22 PM, Warp wrote:
> Orchid Win7 v1<voi### [at] dev null> wrote:
>> public List<Int> foobar(String s)
>
> Btw, why return a list?
>
> I know that memory allocation in C# is probably faster than it is
> in C++, but it still feels odd to use a list instead of something more
> memory-efficient (which C# most certainly ought to support) and faster
> to access. What possible advantage could there be in using a list of
> ints?
>
> Are you transferring your customs of using lists from Haskell to C#?
The C# "List" class actually represents a growable array. So it has O(1)
index and O(1) append until the underlying array needs to be enlarged
(which is obviously O(n) time).
The "LinkedList" class represents a (double-linked) list, with the usual
performance characteristics you would expect for that container.
As best as I can tell, List is pretty much the default container to use
unless you need something more specific.
You could also use a normal array. But that isn't resizable (which
doesn't matter in this particular case).
Post a reply to this message
|
![](/i/fill.gif) |