Rajanikant Hawaldar
What is advisable to use dictionary or list?

What is advisable to use dictionary or list?

By Rajanikant Hawaldar in C# on Jul 14 2021
  • Sonil  Kumar
    Jul, 2021 25

    Dictionary and list has different structure to store the values. List can have duplicate values and it for search using liner algorithm. Hence it is slow. But Dictionary is searching on Key basis so it fast to get the values. If you have unique keys for your objects, use Dictionary. One point I would like to highlight with Dictionary, it is not supporting serialization straight forward, as it is implementing IDictionary interface. You have to write custom logic to do that.

    • 4
  • Shweta Lodha
    Jul, 2021 21

    Both are altogether a different structure. If you are looking for key,value pair then you need dictionary, else list is good to go. If question is with respect to performance, then searching is faster in dictionary

    • 2
  • Rajeev Kumar
    Mar, 2023 17

    List can have duplicate values and it for search using liner algorithm. Hence it is slow. But Dictionary is searching on Key basis so it fast to get the values. If you have unique keys for your objects, use Dictionary.It is more efficient to use dictionaries for the lookup of elements as it is faster than a list and takes less time to traverse.

    • 0
  • Javed Siddiqui
    Feb, 2023 20

    It is advisable to use list as dictionary objects cannot be serialized.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS