Re: Array of string pairs
It is a 2-dimensional array.
You can implement it as
Code:
string[,] Strings; // declaration
...
int n; // number of elements unknown at compile-time
...
// find out n
...
Strings = new string[n,2]; // instantiate array
You can access the elements of the string with Strings[i][0] (first string at index i) and Strings[i][1] (second string at index i).
Re: Array of string pairs
Getting an error...
Code:
string [,] aryKeys = new string[10, 2];
int nKeysGenerated = 0;
//error: CS0022: Wrong number of indices inside [], expected '2'
aryKeys[nKeysGenerated][0] = "key1 first string";
aryKeys[nKeysGenerated++][1] = "key1 second string";
aryKeys[nKeysGenerated][0] = "key2 first string";
aryKeys[nKeysGenerated++][1] = "key2 second string";
And how do I pass a 2-dim array of uknown size by ref?
Code:
int nKeysGenerated = 0;
string[,] aryKeys;
/error: Argument '1': cannot convert from 'ref string[*,*]' to 'ref object'
if (GetKeys(ref aryKeys, out nKeysGenerated))
{
for (int nCur = 0; nCur < nKeysGenerated; nCur++)
{
lstKeys.Items.Add(string.Format("{0},{1}", aryKeys[nCur, 0], aryKeys[nCur, 1]));
}
}
//and the fxn def
public bool GetKeys(ref string[,] aryKeys, out int nKeysGenerated)
Re: Array of string pairs
I found out that you can't pass a multi-dimensional array to a webservice. So I just passed 2 single dimensional arrays. Messy, but it works.