Why is dictionary so much faster than list?

后端 未结 8 1979
盖世英雄少女心
盖世英雄少女心 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:26

    Dictionary uses hashing to search for the data. Each item in the dictionary is stored in buckets of items that contain the same hash. It's a lot quicker.

    Try sorting your list, it will be a a bit quicker then.

提交回复
热议问题