S
Silvers11
Guest
Hello
I have created a 2D array.
I have created a *pointer to that array but are not sure how to return the values from the dimensions when using the pointers for 2D arrays.
The first messagebox shows that I return the value on this dimensions:
arraynums[299, 99999]
How do I return the same for the pointer in the second MessageBox?
Thank you!
unsafe private void button5_Click(object sender, EventArgs e)
{
int[,] arraynums = new int[300, 100000];
for (int i = 0; i < 300; i++)
{
for (int i2 = 0; i2 < 100000; i2++)
{
arraynums[i, i2] = (i + i2);
}
}
MessageBox.Show("This shows correct value: " + arraynums[299, 99999].ToString()); //Shows 100298.
fixed (int* ptr = arraynums)
{
int x = *((int*)(ptr + 299) + 99999);
MessageBox.Show("How do I return the value for this 2D index [299,99999]? " + x.ToString()); //Shows 299 (This should also show 100298)
}
}
Continue reading...
I have created a 2D array.
I have created a *pointer to that array but are not sure how to return the values from the dimensions when using the pointers for 2D arrays.
The first messagebox shows that I return the value on this dimensions:
arraynums[299, 99999]
How do I return the same for the pointer in the second MessageBox?
Thank you!
unsafe private void button5_Click(object sender, EventArgs e)
{
int[,] arraynums = new int[300, 100000];
for (int i = 0; i < 300; i++)
{
for (int i2 = 0; i2 < 100000; i2++)
{
arraynums[i, i2] = (i + i2);
}
}
MessageBox.Show("This shows correct value: " + arraynums[299, 99999].ToString()); //Shows 100298.
fixed (int* ptr = arraynums)
{
int x = *((int*)(ptr + 299) + 99999);
MessageBox.Show("How do I return the value for this 2D index [299,99999]? " + x.ToString()); //Shows 299 (This should also show 100298)
}
}
Continue reading...