what is the difference between list<> and dictionary<> in c#

前端 未结 5 2202
孤独总比滥情好
孤独总比滥情好 2020-12-08 16:00

I have a strange doubt regarding list and dictionary in c#

In a list we add items to list by using the following method

using System.Collections.Gen         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 16:52

    Elements in a list have the following characteristics:

    They maintain their ordering unless explicitly re-ordered (for example, by sorting the list). They can be of any type, and types can be mixed. They are accessed via numeric (zero based) indices. Elements in a Dictionary have the following characteristics:

    Every entry has a key and a value Ordering is not guaranteed Elements are accessed using key values Key values can be of any hashtable type (i.e. not a dict) and types can be mixed Values can be of any type (including other dict’s), and types can be mixed

提交回复
热议问题