Home› X++ Programming Language› / Programs / Map in D365 F&O - X++ Code to Remove element
🚀 Programming Example

Map in D365 F&O - X++ Code to Remove element

141 Views
Beginner
Code Snippet

Remove element – delete, Map in D365 F&O - X++ Code to Remove element – delete

📌 Information & Algorithm

Given Input:

       map.insert (1,"Rumman");
       map.insert (2,"Osman");
       map.insert (3,"Musar");
       map.insert (4,"Inzamamul");
       map.insert (5,"Hassan");

Expected Output:

Value Hassan for key 5
Value Inzamamul for key 4
Value Osman for key 2
Value Rumman for key 1

💻 Program Code

internal final class CodePractice
{
   public static void main(Args _args)
   {
       Map map = new Map (Types::Integer, Types::String);
       MapEnumerator   mapEnum;
       // inserting key and values
       map.insert (1,"Rumman");
       map.insert (2,"Osman");
       map.insert (3,"Musar");
       map.insert (4,"Inzamamul");
       map.insert (5,"Hassan");
          
       if(map.remove(3))
       {
           mapEnum = map.getEnumerator();
           while (mapEnum.moveNext())
           {
               info(strFmt("Value %1 for key %2 ", mapEnum.currentValue(),mapEnum.currentKey()));
           }
       }
   }
 
}

🖥 Program Output

                                Value Hassan for key 5
Value Inzamamul for key 4
Value Osman for key 2
Value Rumman for key 1

                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.