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
Nice, This will be really helpful for business central development.
ReplyDeleteGlad I could help :)
Delete