Greg Gates [mailto:[EMAIL PROTECTED]] wrote:
> 1) Is there any point in using a struct if the struct > contains a string, given that a string is a reference type? Sure, why not? The string itself is on the heap, but, with a struct, the reference to the string and whatever other fields the struct contains *could* be allocated on the stack instead of the heap. > 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 Well you can't sort a Hastable. It's stored according whatever algorithm the implementation used. The importance of a Hashtable is not order, but speed of retrieval by key. I believe you'll need to look outside the BCL for a container algorithm that supports what you're looking for... maybe even have to roll your own. > What is the quickest way to retrieve an ordered subset of the > items where the foo field is less than or equal to 3? Assuming it's a Hashtable, I don't think you can beat O(N) for this. Because of the storage, you'd need to enumerate the entire contents of the Hashtable completely searching for all those <= 3. HTH, Drew .NET MVP You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.