# Dynamic Arrays

Dynamic arrays are a very specific feature of Team Developer. They are similar to [System.Collections.ArrayList](https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist), but can be multidimensional, and can be expanded also by accessing items out of sequence.&#x20;

{% hint style="warning" %}
Using a native *ArrayList* you'd get an exception if the indexed element has not been added to the collection.
{% endhint %}

In the PPJ Framework we have implemented all dynamic array functionality into the *PPJ.Runtime.SalArray class* and have it specialized for each basic type in form of an inner class named Array for .NET 1.1 and using generics in .NET 2.0. In fact, the inner class technique used for .NET 1.1 is a form of generics coding.

```abap
String: strArray[*]
```

Is translated to:

```csharp
SalString.Array strArray = new SalString.Array(); // .NET 1.1
SalArray<SalString> strArray = new  SalArray<SalString>(); // .NET 2.0 and above
```

SAL arrays can also specify multiple dimensions and/or the base index in the initializer.

Arrays declared using base initializers are ported using the overloaded string constructors in order to support the syntax with the colon:

```abap
String: strArray[2:10]
```

Is translated to:

```csharp
// .NET 1.1
SalString.Array strArray = new SalString.Array("2:10");

// .NET 2.0 and above
SalArray<SalString> strArray = new  SalArray<SalString>("2:10");
```

## Array Elements by Reference

Since the *SalArray* class uses the indexer property to access array elements, it is not possible to pass array elements by reference.

Additionally, because of the dynamic nature of SAL arrays, in Team Developer it's also possible to pass by reference an array element that does not exist, causing the array to be extended in line.

The implementation of *SalArray* in the PPJ Framework exposes the *GetArray()* function that returns the inner native array, therefore making it possible to pass elements by reference.

The *GetArray()* function accepts indices as arguments to make sure that the element to be passed by reference is created in the inner array.

For example:

```abap
Call SalGetItemName(hWndItem, strArray[10])
```

Is translated to:

```csharp
Sal.GetItemName(Sys.hWndItem, ref strArray.GetArray(10)[10]);
```

The expression above means that the PPJ Framework first makes sure that there are at least 10 elements in the array, the returns the inner native array, and the tenth \[10] element is then passed by reference to the function.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iceteagroup.com/general/framework/data-types/dynamic-arrays.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
