转换一维阵列的索引成两维阵列岛即行和列 [英] Converting index of one dimensional array into two dimensional array i. e. row and column
问题描述
我有列表框内我插入名称和price..name和价格被分别存储在二维阵列的WinForms的一个应用程序。现在,当我slecet一个记录从列表框中它给了我pnly一个索引从中我能得到的字符串名称和价格......以更新记录我有索引此更改名称和价格,我要同时更新2维数组名称和价格。但选择指数只有一维..我想该索引转化为行和列..how这样做呢?
但I M插入记录IIN列表框中这样的..
INT排= 6,列= 10;的for(int i = 0; I<排;我++)
{
对于(INT J = 0; J<列; J ++)
{
值=行+\\ t+列+\\ t+名[I,J] +\\ t+价格[I,J]。
listbox.items.add(值);
}
}
虽然我没有完全理解的确切情况下,常用的方法1D之间和翻译的二维坐标是:
从2D到1D:
指数= X +(Y *宽)
或
指数= Y +(X *高)
这取决于你是否读从左到右或从上到下。
从一维到二维:
X =索引%的宽度
Y =指数/宽
或
X =指数/身高
Y =指数高度%
I have one application of WinForms which inside list box I am inserting name and price..name and price are stored in two dimensional array respectively. Now when I slecet one record from the listbox it gives me pnly one index from which I can get the string name and price...to update that record I have to change name and price at that index for this I want to update both two dimensional array name and price. but the selected index is only one dimensional.. I want to convert that index into row and column ..how to do that?
But i m inserting record iin list box like this..
int row=6,column=10;
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
value= row+" \t "+ column +" \t "+ name[i,j]+" \t " +price[i,j];
listbox.items.add(value);
}
}
While I didn't fully understand the exact scenario, the common way to translate between 1D and 2D coordinates is:
From 2D to 1D:
index = x + (y * width)
or
index = y + (x * height)
depending on whether you read from left to right or top to bottom.
From 1D to 2D:
x = index % width
y = index / width
or
x = index / height
y = index % height
这篇关于转换一维阵列的索引成两维阵列岛即行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!