十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
每行的数字个数不同,你说的这是不规则数组,解决方案如下:
创新互联-专业网站定制、快速模板网站建设、高性价比云龙网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式云龙网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖云龙地区。费用合理售后完善,10余年实体公司更值得信赖。
Dim b As String = ""
Dim a As Integer()() = New Integer(9)() {}
a(0) = New Integer() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
a(1) = New Integer() {0, 3, 4, 5}
a(2) = New Integer() {0, 4, 5, 6, 7}
a(3) = New Integer() {0, 6, 5, 8, 9, 1}
a(4) = New Integer() {0, 2, 5, 1, 7}
a(5) = New Integer() {0, 4, 2, 6, 7, 3}
a(6) = New Integer() {0, 4, 5, 3, 2}
a(7) = New Integer() {0, 4, 1, 6, 2, 8, 5, 3}
a(8) = New Integer() {0, 4, 9, 6, 3, 5, 7}
a(9) = New Integer() {0, 1, 5, 9, 7, 6, 2, 4, 3, 8}
For i As Integer = 0 To a.GetUpperBound(0)
b = "第" i + 1 "行有" a(i).GetUpperBound(0) + 1 "个数" vbCrLf
Next
MessageBox.Show(b)
根据你的语句,上下标是确定的,所以定义语句修改为:
Dim ary(UBound(temp), 1) As String '声明二维数组
OPCItemIDsData(j,其中一维)即可。
如果前面方法有规定,不能用二维数组的格式,那么你可以自己定义一个一维数组,将二维数组的某一维度的全部数值赋值给这个数组,在引用这个数组:
dim OPCItemIDsDataBuf(x) as ...
for i = 1 to x
OPCItemIDsDataBuf(j)=OPCItemIDsData(j,其中一维)
next i
其中x是数组的最大下标
窗体上添加3个标签,1个按钮,在按钮的单击事件里写代码,如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(,) As Integer = {{5, 6}, {1, 3}, {8, 9}, {72, 1}, {63, 4}}
Dim Temp As Integer
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim y As Integer
'显示排序前的数据
Label1.Text = "排序前数据:" vbCrLf
For i = 0 To 4
Label1.Text = Label1.Text a(i, 0) " " a(i, 1) vbCrLf
Next
For i = 0 To 3
For j = i + 1 To 4
If a(i, 0) a(j, 0) Then
Temp = a(i, 0)
a(i, 0) = a(j, 0)
a(j, 0) = Temp
Temp = a(i, 1)
a(i, 1) = a(j, 1)
a(j, 1) = Temp
End If
Next
Next
'显示排序前的数据
Label2.Text = "排序后数据:" vbCrLf
For i = 0 To 4
Label2.Text = Label2.Text a(i, 0) " " a(i, 1) vbCrLf
Next
'把第3行元素赋予X,Y
x = a(2, 0)
y = a(2, 1)
'输出X,Y
Label3.Text = "X=" x vbCrLf "Y=" y
End Sub
将二位数组转成DataTable,网上找的不知道成不成
public static DataTable ConvertToDataTable(string[,] arr)
{
DataTable dataSouce = new DataTable();
for (int i = 0; i arr.GetLength(1); i++)
{
DataColumn newColumn = new DataColumn(i.ToString(), arr[0, 0].GetType());
dataSouce.Columns.Add(newColumn);
}
for (int i = 0; i arr.GetLength(0); i++)
{
DataRow newRow = dataSouce.NewRow();
for (int j = 0; j arr.GetLength(1); j++)
{
newRow[j.ToString()] = arr[i, j];
}
dataSouce.Rows.Add(newRow);
}
return dataSouce;
}
for i =0 to ...
for j =0 to ...
keyarray(i,j)=
next
next
双重循环,赋值和读取一样