--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
Chua Wen Ching said:
Hi Richard A. Lowe,
Thanks for the reply. Can you please check inlines?
1) profiling the performance of you application
--> Yeah i had used the clr profiler. Kind of confusing. Many diagrams and
confusing. Any good tips to learn it up. Thanks
I'm not expert in that app, I'm afraid. I usually just pick a section of
code and time it in my code, I'm afraid.
2) retrieve it by key or just by index?
--> Index by key. I had specific keys to check the tables. And are you
refering hashtable or any collections?
Great, you should use the Hashtable. Use the contstructor that has the int
and float parameters: the int is the initial capacity: the number of items
you think you will need. The loadfactor is a number that tells the
Hashtable how to balance speed vs. size. Set it to it's minimum value for
the greatest speed: 0.1f:
new Hashtable(numberOfItemsINeed, 0.1f);
3) What is your most frequent used collections?
Well, probably typed collections derived from CollectionBase
4) simply store a class that holds two values i.e.:
myHashtable.Add("key", new MyValue("val1", "val2"));
--> new MyValue, is this a constructor or a new class? Can you show some
snippets please? Thanks.
Yes, that's what it is - a custom class of yours. i.e.
class MyValue {
public MyValue(object key, object value) { // etc - make public fields
or properties here to give you the values }
}
5)
--> Oh you can overload the add. Hmm... i tried to override it. But i not
sure how? Do i need to inherit something then i can override it?
If you inherit from Hashtable you can add overloads, no need to override:
class MyValueHashtable : Hashtable
{
public void Add(object key, object value) { // etc... call the other Add
method, and construct a MyValue instance to store two values here }
}
Thanks a lot again.