Tuesday, February 12, 2008

KeyValueConfigurationElement VS NameValueConfigurationElement

After checking on the description form MSDN, http://msdn2.microsoft.com/en-us/library/system.configuration.namevalueconfigurationelement(VS.80).aspx

It is written that
"
There is a difference between the NameValueConfigurationElement class and KeyValueConfigurationElement class. The NameValueConfigurationElement class does not require the first string to be unique, whereas KeyValueConfigurationElement class requires the first string to be a key, and therefore unique in the collection.
"

However when I try to test it, it seems that
  1. NameValue also can not display duplicate Names in the collection moreover if the name is the same but the value is different , it will throw an error message which says that name has already has the value.
  2. On the other hand KeyPair, also can not have duplicate keys but if there is duplicate key but different values, it will be override with the last values. There is no error message return.
  3. KeyPair collection will be sorted , I guess it similar with Hashtable collection but NameValue is not sorted.
  4. KeyPair is case sensitive so Key1 and key1 will be consider the same key
    but Namevalue is incase sensitive Name1 and name1 will be consider different name

For solving this problem, I have build my custom collection - can be downloaded at
http://kkurni.googlepages.com/KKurni.CustomConfigurationElementCol.rar

No comments: