I'm trying to display a matrix (which is stored as an array) in a label on a visual basic form and I don't know if there is a simple command to do this. I can output all of the numbers in a line on the label, but I want it to be formatted. I could insert and line return (but I don't know the code), but what I would really like to do is display the whole array with one command if that command exisits. Help!
Displaying a 2-D array in a label
Collapse
X
-
Hope this helps. There is a form with 2 controls: label1, button1. The code is C#, but the idea is the same. There could be a better way.
Code:private void button1_Click( object sender, EventArgs e ) { int[][] arr = new int[][] { new int[]{0,1}, new int[]{2,3}, new int[]{4,5}, new int[]{6,7}}; for(int r = 0; r < arr.Length; r++) { label1.Text += "{ "; for(int c = 0; c <= arr.Rank; c++) { label1.Text += arr[r][c].ToString() + " "; } label1.Text += "}" +Environment.NewLine; } }
Comment