我必须将前队友的vb代码转换为C#asp.net代码。我发现有一个数组 ls_data ,它包含很多字符串数组,但是像一维数组一样暗淡
lf_save_data_F(ByVal IntelKind As String, ByVal FilewriteTime As String, ByVal Part As String, ByVal Lot As String, ByVal Machine As String, ByVal WorkClass As String, ByVal MeasureOrNot_Bp As Boolean, ByVal MeasureOrNot_Ltp As Boolean, ByVal value_S_co() As String, ByVal value_S_co_x() As String, ByVal value_S_co_y() As String, ByVal value_P_so() As String, ByVal value_S_so() As String, ByVal value_S_so_x() As String, ByVal value_S_so_y() As String, ByVal value_D_so() As String, ByVal value_L_so() As String, ByVal judge_S_co As String, ByVal judge_S_co_x As String, ByVal judge_S_co_y As String, ByVal judge_P_so As String, ByVal judge_S_so As String, ByVal judge_S_so_x As String, ByVal judge_S_so_y As String, ByVal judge_D_so As String, ByVal judge_L_so As String, ByVal dt_spec_S_co As DataTable, ByVal dt_spec_S_co_x As DataTable, ByVal dt_spec_S_co_y As DataTable, ByVal dt_spec_P_so As DataTable, ByVal dt_spec_S_so As DataTable, ByVal dt_spec_S_so_x As DataTable, ByVal dt_spec_S_so_y As DataTable, ByVal dt_spec_D_so As DataTable, ByVal d_spec_L_so As DataTable) As Long
Dim ls_data() As Array = {value_S_co, value_S_co_x, value_S_co_y, value_P_so, value_S_so, value_S_so_x, value_S_so_y, value_D_so, value_L_so}
它看起来像是C#形式
Array[] ls_data = {
value_S_co,
value_S_co_x,
value_S_co_y,
value_P_so,
value_S_so,
value_S_so_x,
value_S_so_y,
value_D_so,
value_L_so
};
这就是我的前队友使用它的方式。
For li_k = 1 To ls_data(li_j - 1).Length
ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + ls_data(li_j - 1)(li_k - 1) + ","
,但以C#格式将其转换为ls_data[li_j - 1, li_k - 1]
无法编译。由于 ls_data 是一维数组,我该如何解决?
这是li_j集
For li_j = 1 To ls_data.Length
If lb_insert(li_j - 1) = True Then
//Combine SQC data
ls_Str_Tester = ""
ls_Str_Value = ""
For li_k = 1 To ls_data(li_j - 1).Length
ls_Str_Tester = ls_Str_Tester + "Auto-SQV,"
ls_Str_Value = ls_Str_Value + ls_data(li_j - 1)(li_k - 1) + ","
Next
ls_Str_Tester = Mid(ls_Str_Tester, 1, Len(ls_Str_Tester) - 1)
ls_Str_Value = Mid(ls_Str_Value, 1, Len(ls_Str_Value) - 1)
li_RestCount = 20 - ls_data(li_j - 1).Length
For li_RestCountInt = 1 To li_RestCount
ls_Str_Tester = ls_Str_Tester + ","
ls_Str_Value = ls_Str_Value + ","
Next
//Combine SQL
ls_sql1(li_j - 1) = "insert into sqcresult(DeptName,Process,PartNo,Lot,machinename,ActualInputTime,InputDate,Tester,judgment,ItemNo,SpecID,SetTime2,ItemName,SpecName,Str_Color,Str_Tester,Str_Value,"
If Not ldt_spec(li_j - 1).Rows(0).Item("xusl") Is System.DBNull.Value Then ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + "xusl,"
If Not ldt_spec(li_j - 1).Rows(0).Item("xlsl") Is System.DBNull.Value Then ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + "xlsl,"
For li_k = 1 To ls_data(li_j - 1).Length
ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + "InputResult" + Format(li_k, "0") + ","
Next
ls_sql1(li_j - 1) = Mid(ls_sql1(li_j - 1), 1, Len(ls_sql1(li_j - 1)) - 1) + ") values ('" + gs_user_dept + "','" + gs_user_process + "','" + UCase(ls_part(li_j - 1)) + "','" + UCase(Lot) + "','" + Trim(gdt_supervisor.Rows(0).Item("measure_machineno")) + "','" + Format(CDate(FilewriteTime), "yyyy/MM/dd HH:mm:ss") + "','" + Format(CDate(FilewriteTime), "yyyy/MM/dd") + "','Auto-SQV-" + gs_user_id + "','" + ls_judge(li_j - 1) + "'," + CStr(ldt_spec(li_j - 1).Rows(0).Item("itemno")) + "," + CStr(ldt_spec(li_j - 1).Rows(0).Item("specid")) + ",'" + Format(CDate(ldt_spec(li_j - 1).Rows(0).Item("settime")), "yyyy/MM/dd HH:mm:ss") + "','" + ldt_spec(li_j - 1).Rows(0).Item("itemname") + "','" + ldt_spec(li_j - 1).Rows(0).Item("specname") + "','" + ls_Str_Color + "','" + ls_Str_Tester + "','" + ls_Str_Value + "',"
If Not ldt_spec(li_j - 1).Rows(0).Item("xusl") Is System.DBNull.Value Then ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + CStr(ldt_spec(li_j - 1).Rows(0).Item("xusl")) + ","
If Not ldt_spec(li_j - 1).Rows(0).Item("xlsl") Is System.DBNull.Value Then ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + CStr(ldt_spec(li_j - 1).Rows(0).Item("xlsl")) + ","
For li_k = 1 To ls_data(li_j - 1).Length
ls_sql1(li_j - 1) = ls_sql1(li_j - 1) + ls_data(li_j - 1)(li_k - 1) + ","
Next
ls_sql1(li_j - 1) = Mid(ls_sql1(li_j - 1), 1, Len(ls_sql1(li_j - 1)) - 1) + ")"
End If
答案 0 :(得分:0)
VB.NET代码显示了锯齿状的对象数组,而不是2D数组。文章VB.NET 2D, 3D and Jagged array examples解释了差异。
Array
是 all 数组的基类。问题的代码本质上以一种非常不寻常的方式声明了锯齿状的对象数组。声明锯齿状对象数组的常见方法是:
Dim ls_data()() As Object
除非有人想混合使用字符串和整数数组,否则应使用一种特定的类型:
Dim ls_data()() As String
C#中的等效项非常相似:
string[][] ls_data;
在两种情况下,要从内部数组中检索元素,必须先找到该数组,然后提取该元素。以下两个表达式都访问VB.NET中第二个嵌套数组的第三个元素:
ls_data(1)(2)
和C#
ls_data[1][2]
两种语言的多维数组都是用逗号分隔的维列表定义的:
Dim ls_data(,) As String = New String(,) {{"ant", "aunt"},
{"Sam", "Samantha"},
{"clozapine", "quetiapine"},
{"flomax", "volmax"},
{"toradol", "tramadol"}}
在C#中:
string[,] ls_data(,) = new string[,] {{"ant", "aunt"},
{"Sam", "Samantha"},
{"clozapine", "quetiapine"},
{"flomax", "volmax"},
{"toradol", "tramadol"}};