简体   繁体   English

Array.Length 不能分配给 - 它是只读的

[英]Array.Length cannot be assigned to — it is read only

I am trying to include a script task in my ssis package that continuously checks a folder until a specified file is placed there, at which point it succeeds and goes on to the next step in the package.我正在尝试在我的 ssis package 中包含一个脚本任务,该任务不断检查一个文件夹,直到将指定的文件放置在那里,此时它成功并继续执行 ZEFE90A8E604A7C840E88D03A6D7 中的下一步。 Here is the code I am using in the script task:这是我在脚本任务中使用的代码:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO;

namespace ST_6a16f1bd9a6548ddb82bbf41d5d5006f
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]

public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

    public void Main()
    {
        bool foundFile = false;
        string[] files = Directory.GetFiles(@"directory", "*abcd*");

        while (files.Length = 0)
            {
                foundFile = false;
            }

        if (files.Length > 0)
            { 
                foundFile = true;
            }

        if (foundFile == true)
            {
                Dts.TaskResult = (int)ScriptResults.Success;
            }
    }

    enum ScriptResults
    {
        Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
        Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };

}

} However, when I build this code, I get the error "Property or indexer 'Array.Length' cannot be assigned to -- it is read only".但是,当我构建此代码时,我收到错误“无法将属性或索引器 'Array.Length' 分配给 -- 它是只读的”。

Instead of代替

while (files.Length = 0)

Use利用

while (files.Length == 0)

You assigned 0 to files.Length instead of testing it.您将 0 分配给 files.Length 而不是对其进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM