1) Yes.  Value types have an inherently lower cost.  They are cheaper to
create/destroy, cheaper to maintain, and (most of the time) cheaper to use.

2) A Hashtable isn't really suited to sorting or filtering.  It's actually
better if the keys in a hashtable are as unsorted as possible, because this
allows optimal searching of its values.  The quickest way to get your subset
would be from a list pre-sorted on the value of the 'foo' field, then you'd
only have to enumerate the matching objects.  If you need a list that
remains sorted all the time, try SortedList, although it can slow things
done quite a bit.  Array.Sort() will sort any array based on an IComparer,
or on the objects' own ICompaable implementation.

Jim

> -----Original Message-----
> From: Greg Gates [mailto:[EMAIL PROTECTED]]
> Sent: 23 May 2002 16:24
> To: [EMAIL PROTECTED]
> Subject: [DOTNET] Hashtables and structs
>
>
> Hello everyone:
>
> I have two basic questions regarding hashtables and structs.
>
> 1) Is there any point in using a struct if the struct
> contains a string,
> given that a string is a reference type?
>
> 2) What is the most efficent way to sort and filter a
> hashtable in .NET.
> For example, if I have a hashtable that contains the
> following key/values:
>
> A,object1
> B,object2
> C,object3
>
> object1 has a foo field with a value of 4
> object2 has a foo field with a value of 1
> object3 has a foo field with a value of 2
>
> What is the quickest way to retrieve an ordered subset of the
> items where
> the foo field is less than or equal to 3?
>
> thanks, Greg
>
> You can read messages from the DOTNET archive, unsubscribe
> from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to