Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

if (!int.TryParse(carmake.Text, out store[0]))
MessageBox.Show("type an integer ");

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

May be this will help you or you'll get some idea

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]);
Share this answer
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 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 :)
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>.
Share this answer
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900