0
public bool function()
{
    bool doesExist = false;          
    BackgroundWorker worker = new BackgroundWorker();
    worker.DoWork += (o, ea) =>
        {
            // some work done here
        };

    worker.RunWorkerCompleted += (o, ea) =>
        {
            //somw logic here
            return doesExist;                               
        };
} 

doesExist関数の戻り値としての値が必要ですが、インテリセンス エラーが発生しています

system.componentmodel. runworkercompletedeventhandler は void のみを返します。return キーワードの後に​​オブジェクト式を続けてはなりません

このエラーが発生するのはなぜですか、ブール値を返す方法は?

4

1 に答える 1

2
public bool function()
{
   bool doesExist = false;          
   BackgroundWorker worker = new BackgroundWorker();

   worker.DoWork += (o, ea) =>
            {
                 // do some work
                 ea.Result = true; // set this as true if all goes well!
            };

    worker.RunWorkerCompleted += (o, ea) =>
        {
              // since the boolean value is calculated here &
              // RunWorkerCompleted returns void
              // you can create a method with boolean parameter that handle the result.
              Another_Way_To_Return_Boolean(doesExist)


        };
} 


private void Another_Way_To_Return_Boolean(bool result)
{
    if (result)
    {

    }
}
于 2013-03-04T10:26:46.750 に答える