【问题标题】:Cannot implicitly convert type 'string' to 'string[]' again [closed]无法再次将类型“字符串”隐式转换为“字符串 []”[关闭]
【发布时间】:2022-01-24 18:13:20
【问题描述】:

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

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

来自this article,一个自定义的Taskmgr

我需要将此变量传递给 Form 1,但我无法将其公开,所以我创建了

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]; 这显然很明显,我以为我已经尝试过了,但它奏效了。

【问题讨论】:

    标签: c# visual-studio winforms visual-studio-2022


    【解决方案1】:

    您还必须指定接收索引:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-09
        相关资源
        最近更新 更多