2

I was trying to declare an array of strings like so:

str ar1[2] = ['One','Two'];

Getting a syntax error. How can I initialize and assign an array like above?

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78

2 Answers2

4

['One', 'Two'] is a container in the axapta. axapta has no syntax for initialize an array. use:

str ar1[2];

ar1[1] = 'One';
ar1[2] = 'Two';
mazzy
  • 1,025
  • 1
  • 13
  • 26
4

In AX, you'r trying to assign a container collection to an array collection. Which is incorrect, Therefore you can try to follow one of the approach listed below:

Using an array:

str number[2];

// Array starts at one in AX; hence number[0] will clear every value in the array
number[1] = 'One';
number[2] = 'Two';

The other way, would be to use a container:

container con;

con += 'One';  // Equivalent to 'con = conIns(con, conLen(con)+1, 'One');
con += 'Two';  // Equivalent to 'con = conIns(con, conLen(con)+1, 'Two');

or a shortcut would be to use:

container con = ['One', 'Two'];
Danyal Imran
  • 2,515
  • 13
  • 21
  • 1
    remember that [Container are immutable](https://msdn.microsoft.com/en-us/library/aa874816.aspx): > Some X++ statements with containers might appear like they modify a container, but inside the system this never occurs. Instead, the data from the original container is combined with data from the command to build a *new* container. – mazzy May 28 '18 at 11:05