IDictionary or NameValueCollection

后端 未结 4 1775
南笙
南笙 2021-01-01 09:59

I have a scenario where-in I can use either NameValueCollection or IDictionary. But I would like to know which one will be better performance-wise.

-- Using NameValu

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 10:16

    These collection types are not exactly interchangeable: NameValueCollection allows access via integer indexes. If you don't need that functionality, you shouldn't use a NameValueCollection as indexing doesn't come "for free".

    Depending on the number of strings you're looking at, I would consider either Hashtable or IDictionary. Krzysztof Cwalina discusses the subtleties here: http://blogs.gotdotnet.com/kcwalina/archive/2004/08/06/210297.aspx.

提交回复
热议问题