Why is dictionary so much faster than list?

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

    Dictionary is based on a hash table which is a rather efficient algorithm to look up things. In a list you have to go element by element in order to find something.

    It's all a matter of data organization...

提交回复
热议问题