In my last Hashtable & serialization example, you my have noticed a Hashtable addition that has a different approach then the retrival.
for addition we used: myCollection.add(mn,ad);
for retrival we used: ad = myCollection[mn];
where myCollection is the hashtable, mn and ad are structs.
i got an email saying that an addition could be performed as such: myCollection[mn]=ad; and that is correct and excellent, but lets point the differences between property addition and add method:
While using a property addition (eg myCollection[mn]=ad;) we can add new items, However, if the specified key already exists in the Hashtable, setting the Item property overwrites the old value. In contrast, the Add method does not modify existing elements, and if the item exists, an exception is thrown.
hope that clears things up.
12:04:11 PM
|