is it possible to create Two dimension and two type Array ?

 

In MQL4 is it possible to create a two-dimensional array whose first dimension is a number and the second is a string? If the answer is yes, is there a way to sort it?

Like this :

Array[4][4] = {{"USD",1},{"EUR",4},{"NZD",3},{"CAD",2}};

and after sort :

Array[4][4] = {{"USD",1}, {"CAD",2} ,{"NZD",3}, {"EUR",4} }; 

Improperly formatted code edited by moderator. Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Create a struct, and then an array of that struct
 
Shahriar Soltani: In MQL4 is it possible to create a two-dimensional array whose first dimension is a number and the second is a string? If the answer is yes, is there a way to sort it?
  1. The logical way, as suggested by Fabio, means you can't use thee built in sort. Instead you have to use my insertion sort (non-pointer) method.
              Sort multiple arrays - MQL4 programming forum #9
              Array or not to array - Trading Positions - MQL4 programming forum - Page 2 #20.4

    Or (object pointer) CList method:
              pass generic class data field - Swing Trades - MQL4 programming forum

  2. Alternatively, make an index, and then sort.

    string names[] = {"USD", "EUR", "NZD", "CAD"};
    //                  0      1      2      3
    Array[][2] = {1,0}, {4,1}, {3,2}, {2,3} };
    
    // and after sort :
    Array[][2] = {1,0}, {2,3}, {3,2}, {4,1} }; // names[ array[1][1] ] == "CAD"

    Remember the built in sort, sorts by the first index, not the last.

 
Fabio Cavalloni #:
Create a struct, and then an array of that struct
Many Thanks Fabio , I learned about struct .
 
William Roeder #:
  1. The logical way, as suggested by Fabio, means you can't use thee built in sort. Instead you have to use my insertion sort (non-pointer) method.
              Sort multiple arrays - MQL4 programming forum #9
              Array or not to array - Trading Positions - MQL4 programming forum - Page 2 #20.4

    Or (object pointer) CList method:
              pass generic class data field - Swing Trades - MQL4 programming forum

  2. Alternatively, make an index, and then sort.

    Remember the built in sort, sorts by the first index, not the last.

Thank you so much William , very useful comment and topics. :)