In Microsoft Dynamics NAV, a common development task is to write code that loops through a set of records and performs an operation on each record in the set. You can do the same task in the .NET Framework with a collection, which is a .NET Framework object that you can iterate over. To loop through a collection in Microsoft Dynamics NAV, the .NET Framework object must support the System.Collections interface. Many types in the .NET Framework and assemblies that inherit from .NET Framework types support the System.Collections interface. The following example shows how you can write C/AL code to handle collections for a type that supports the System.Collections interface.
The following example implements the System.ArrayList interface and uses the GetProcesses method from the System.Diagnostics.Process type to display a list of process IDs in message boxes. Although this is not a typical example for an ERP product such as Microsoft Dynamics NAV, it shows the flexibility that you get with the .NET Framework.
The example requires that you define the following C/AL variables.
'mscorlib, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array
'System, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Diagnostics.Process
MyProcessList := Process.GetProcesses(); FOR I:=0 TO (MyProcessList.Length()-1) DO BEGIN Process := MyProcessList.GetValue(I); MESSAGE(FORMAT(Process.Id)); END;