C
C#•2y ago
FloW

every generated textBox has a diferent value but all arrey values is 0 .

Why?
13 Replies
SinFluxx
SinFluxx•2y ago
$details
MODiX
MODiX•2y ago
When you ask a question, make sure you include as much detail as possible. Such as code, the issue you are facing, and what you expect the result to be. Upload code here https://paste.mod.gg/ (see $code for more information on how to paste your code)
FloW
FloWOP•2y ago
No description
No description
FloW
FloWOP•2y ago
I know , just forget to make screenshots šŸ˜…
SinFluxx
SinFluxx•2y ago
I mean, they're not really that helpful either
FloW
FloWOP•2y ago
can I paste code ?
SinFluxx
SinFluxx•2y ago
$code
MODiX
MODiX•2y ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
FloW
FloWOP•2y ago
thank you!
int[] arr = new int[300];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr.Append(TextNum);
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
}
int[] arr = new int[300];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr.Append(TextNum);
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<arr.Length; i++)
{
Console.WriteLine(arr[i]);
}
}
😊
SinFluxx
SinFluxx•2y ago
arr.Append(TextNum); Append will create a new sequence, it won't add anything into your existing arr variable Even if you updated arr to be the new sequence that Append gives you, because you've declared arr with a size of 300, you'll end up with an array of 300 0s and then the new TextNum value on the end
FloW
FloWOP•2y ago
so arr[301] will be TextNum right?
SinFluxx
SinFluxx•2y ago
that's right - if you make sure to assign the newly created sequence to your arr variable What would probably make more sense is trying to set the value at the index of the array you're currently at? arr[0] = TextNum, arr[1] = TextNum, etc?
FloW
FloWOP•2y ago
hm i tried to do it using for I`ll try again , thank you one more question I need to change int[300] to int[0] or no?
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i * j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i * j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}
what do you think? update:
int[,] arr = new int[15, 20];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i, j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<15; i++)
{
for (int j = 0; j < 20; j++)
{
Console.WriteLine(arr[i, j]);
}
}
}
int[,] arr = new int[15, 20];
private void button1_Click(object sender, EventArgs e)
{
Random randomGenerator = new Random();
for (int i = 0; i<15; i++)
{
for (int j = 0; j<20; j++)
{
int TextNum = randomGenerator.Next((int)numericUpDown1.Value, (int)numericUpDown2.Value);
arr[i, j] = TextNum;
TextBox textBox = new TextBox()
{
Text = TextNum.ToString(),
Location = new Point(40 + 105 * i, 40 + 30 * j),
Width = 100,
Height = 25,
};

Controls.Add(textBox);
}
}

for (int i=0; i<15; i++)
{
for (int j = 0; j < 20; j++)
{
Console.WriteLine(arr[i, j]);
}
}
}
its working Thank you very much!

Did you find this page helpful?