为了账号安全,请及时绑定邮箱和手机立即绑定

VB 的二维字符串数组到 C# ASP.NET

VB 的二维字符串数组到 C# ASP.NET

C#
FFIVE 2022-06-19 16:31:50
我必须将我前队友的 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 LongDim 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是一维数组,我该如何解决这个问题?
查看完整描述

1 回答

?
胡子哥哥

TA贡献1825条经验 获得超6个赞

VB.NET 代码显示了一个锯齿状的对象数组,而不是二维数组。VB.NET 2D、3D 和锯齿状数组示例一文解释了这些差异。


Array是所有数组的基类。问题的代码本质上以一种相当不寻常的方式声明了一个参差不齐的对象数组。声明锯齿状对象数组的常用方法是:


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"}};


查看完整回答
反对 回复 2022-06-19
  • 1 回答
  • 0 关注
  • 145 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信