C#需要传递一个数组';s转换为另一种形式
本文关键字:转换 另一种 数组 一个 | 更新日期: 2023-09-27 18:24:39
我想将一个数组传递给另一个Form
String[] arrayOfStrings = new String[4];
arrayOfStrings[0] = td1stcolumn[];
arrayOfStrings[1] = td2ndcolumn[];
arrayOfStrings[2] = td3rdcolumn[];
arrayOfStrings[3] = td4thcolumn[];
string resultDialogString = ResultDialog.ShowBox(arrayOfStrings, "Result Page");
td1stcolumn、td2ndcolumn、td3rdcolumn和td4thcolumn都是字符串数组
C#在td…列的[]中需要值
ResultDialog.ShowBox的签名是
public static string ShowBox(string[] arrayOfMessages, string txtTitle)
但我可以修改签名。我只需要从传输数据
td1st柱、td2nd柱、td3r柱和td4t柱
显示方法
假设您已经像这样声明了您的"td"变量:
string[] td1stcolumn;
string[] td2ndcolumn;
string[] td3rdcolumn;
string[] td4thcolumn;
然后,您可以将这些值分配给arrayOfStrings
,如下所示:
arrayOfStrings[0] = td1stcolumn;
arrayOfStrings[1] = td2ndcolumn;
arrayOfStrings[2] = td3rdcolumn;
arrayOfStrings[3] = td4thcolumn;
您还需要将字符串数组的声明更改为以下内容:
// an array of arrays. Each array must be the same length.
// your situation calls for a jagged array though.
string[,] arrayOfStrings;
或
// jagged array. each array can be of varying length.
string[][] arrayOfSTrings;
多维阵列文档
锯齿阵列文档
锯齿阵列使用示例:
string[][] arr = new string[2][];
arr[0] = new [] {"a", "b", "c", "d"};
arr[1] = new [] {"a", "b", "c", "d"};
似乎更适合多维数组。。。
// declare
String[,] multiArray = new String[4,4];
// use
string s = multiArray[2,2];