Monday, May 31, 2021

Dictionary Datatype in Microsoft Dynamics Business Central

Hi All, 

I hope you'll are doing well. 

Business Central has been adapting a lot from Object Oriented Language and moving closer to most of the functions and features. Dictionary is one of those and is a very useful data type. 

Lets go into details and understand it. I’ll try to put it as simply as possible :)

What is a Dictionary?

It is a collection of (key,value) pair. 

Why Dictionary?

It is an unordered list and helps you to look up faster for a value. It has different methods which you can use. For example, if you want to insert, add a (key,value) pair to a dictionary and fetch is according to the key. Key can be considered as a primary key since the keys of values are unique.

How is it different from List (know more about lists:https://jyotsnanav.blogspot.com/2021/03/return-list-variable-by-pass-by.html) or arrays?

Lists and arrays follow ordered sequence whereas Dictionary is an unordered list and the values are associated to their keys. 

How to implement and use Dictionary?

Syntax: Dictionary of [Datatype,Datatype]

Example:

var

    TestDictionary: Dictionaty of [Integer.Text]

where, Integer = key, Text = value 

Note: They datatypes can be same or different

Use methods()-

TestDictionaty.Add(Key:1,Value:'Test1')

TestDictionary.Count()

TestDictionaty.ContainsKey(Key:1)

TestDictionary.Get(1);

You can find more here: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/dictionary/dictionary-data-type

Hope this blog was helpful. See you until next time. :) 

Check out other blogs, if you haven't already. 

Please suggest what else do you want me to blog about. Keep following and supporting!

You can also email me at jyotsnaoberainav@gmail.com

Also, visit my website JONAV if you are looking for NAV/D365BC Training and/or Services!

Thank you! 

2 comments: