Why is dictionary so much faster than list?

后端 未结 8 2008
盖世英雄少女心
盖世英雄少女心 2020-12-04 18:37

I am testing the speed of getting data from Dictionary VS list.
I\'ve used this code to test :

    internal class Program
{
    private static void Mai         


        
8条回答
  •  没有蜡笔的小新
    2020-12-04 19:37

    When using Dictionary you are using a key to retrieve your information, which enables it to find it more efficiently, with List you are using Single Linq expression, which since it is a list, has no other option other than to look in entire list for wanted the item.

提交回复
热议问题