15,936,709 members
See more:
I have a text box that takes two numbers separated by a comma. For eg: "05, 2004".
I have a two dimensional array called store[i][j] of integer type.
I would like to store 10 in ith position and 2010 in jth position.
such that, store[0][0] should be equal to "05, 2010"
So far, I've only been learning and dealing with one dimensionl array,
and have been using the following statement to read values from a textbox.

C#
```if (!int.TryParse(carmake.Text, out store[0]))
MessageBox.Show(&quot;type an integer &quot;);```

Any help would be much appreciated. Thanks
Posted
Updated 12-Sep-11 0:30am
v3

## Solution 1

Hi,

C#
```string textBox = "45,78";
int[,] values = new int[1,2];
string[] textBoxSplit = textBox.Split(',');
values[0, 0] = Convert.ToInt32(textBoxSplit[0]);
values[0, 1] = Convert.ToInt32(textBoxSplit[1]);```

steersteer 12-Sep-11 6:52am
Thanks for your reply, but I am afraid that Split(); method is not available to textbox control in WPF. I tried with "carmake.Split(','); but I get an error that the System.windows.Controls does not contain a definition for that method. Any thought about it ?
BobJanova 12-Sep-11 10:19am
Look carefully, textBox in this sample is a -string-.
Syed Salman Raza Zaidi 12-Sep-11 6:57am
Try this,use textbox value in a string and then spliting that string it will surely help you :)

## Solution 2

Two dimensional arrays are used to construct matrices. And at teach point in the array, you could still only save one item. Example:

[0][0] : "5, 2010" | [0][1] : "6, 2010"
[1][0] : "5, 2011" | [1][1] : "6, 2011"

What I think you would need to look at is either `List<KeyValuePair<int, int>>` or `Tuple<int, int>`.

v2
steersteer 12-Sep-11 6:58am
Thanks. Very good example. Easy to understand for an amateur like me. Please see if you could answer my other question about controls in WPF.
KenBonny 12-Sep-11 7:14am
Sorry mate, never worked with WPF before.
BobJanova 12-Sep-11 10:18am
I updated this solution to display the type chevrons properly. Use HTML entities (&lt;/&gt;) to get them.
KenBonny 13-Sep-11 2:07am
Cheers. Didn't know I had to use those. It's been a looong time... since I've used those.