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

前端 未结 5 2199
孤独总比滥情好
孤独总比滥情好 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:37

    • Dictionary is an associative array, or map. It is a container that can be indexed by values of any type.
    • List is an integer indexed array. It is a container that is indexed by contiguous integers.

    The essential difference therefore is in how the containers are indexed.

    Don't fall into the trap of believing that Dictionary is semantically equivalent to List. The difference is that the indexing of List is contiguous whereas there can be gaps in the indexing for Dictionary.

提交回复
热议问题