无法再次将类型 'string' 隐式转换为 'string[]'

Cannot implicitly convert type 'string' to 'string[]' again

Form2 中,我有这个变量,我尝试了所有的方法,任何修改都会导致错误:

            string[] row = {
            ProcessName[Index],
            process.Id.ToString(),
            status,
            BytesToReadableValue(process.PrivateMemorySize64),
            extraProcessInfo.Username,
            extraProcessInfo.Description
            };

来自 this article,自定义 Taskmgr

我需要将此变量传递给 Form 1,但我做不到 public 所以我创建了

public static string[] Row;
Row = row;

所以在 Form 1 中我做了以下操作: string[] ROW = Form2.Row; 这实际上不会导致错误(是的,如果你问我,这些非常创意变量名称)。


但我需要将Row的所有值存储在ROW中;我试过

int Index = 1;

string[] ROW = new string[10];
ROW[Index] = AddForm.Row[];

Index++;

但我经常收到错误消息“无法将类型 'string' 隐式转换为 'string[]'”。

解决方法: 像这样加一个0: AddForm.Row[0]; 很明显,我以为我已经试过了,但是成功了。

您还必须指定接收索引:

ROW[0] = AddForm.Row[0];

根据您的逻辑,您可以为 0 s 使用索引。

ROW 的类型为 string[],而 AddForm.Row[0] 的类型为 string。我假设您打算将其分配给有效的 ROW 的第一个索引。

string[] ROW = new string[10];
ROW[0] = AddForm.Row[0];