Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么检测到第二个IF语句是不可访问的代码?_C#_.net_Winforms - Fatal编程技术网

C# 为什么检测到第二个IF语句是不可访问的代码?

C# 为什么检测到第二个IF语句是不可访问的代码?,c#,.net,winforms,C#,.net,Winforms,“if”带有绿色下划线,表示检测到无法访问的代码。 如何修复它以及为什么它是无法访问的代码 也许我需要使用result=而不是return?但这似乎不是问题所在。因为您的返回声明。它将停止if/else流量。也许您正在搜索以下内容: if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully") 因为你的返回声明。它将停止if/else流量。也许您正在搜索以下内容: if (Youtube_Uploader.file

“if”带有绿色下划线,表示检测到无法访问的代码。 如何修复它以及为什么它是无法访问的代码


也许我需要使用result=而不是return?但这似乎不是问题所在。

因为您的返回声明。它将停止if/else流量。也许您正在搜索以下内容:

if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully")

因为你的返回声明。它将停止if/else流量。也许您正在搜索以下内容:

if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully")

因为除此之外,您还有:

if (Youtube_Uploader.fileuploadstatus == "uploading file")
                    {
                        Youtube_Uploader.fileuploadstatus = "";
                        return "uploading";
                    }
                    else if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully")
                    {
                        Youtube_Uploader.fileuploadstatus = "";
                        return "upload completed";
                    }                   
                    else
                    {
                        return "upload unknown state";
                    }
if或else为true,因此代码将从该块返回,并且下面的代码将不会执行

您有三个选项,因此您似乎在寻找一个在本例中可读性最好的开关:

if (...)
{
    return "uploading";
}
else
{
    return "upload unknown state";
}

或者使用字典将服务状态转换为应用程序状态,或者按照建议使用if-else-if-else

因为除此之外,您还有:

if (Youtube_Uploader.fileuploadstatus == "uploading file")
                    {
                        Youtube_Uploader.fileuploadstatus = "";
                        return "uploading";
                    }
                    else if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully")
                    {
                        Youtube_Uploader.fileuploadstatus = "";
                        return "upload completed";
                    }                   
                    else
                    {
                        return "upload unknown state";
                    }
if或else为true,因此代码将从该块返回,并且下面的代码将不会执行

您有三个选项,因此您似乎在寻找一个在本例中可读性最好的开关:

if (...)
{
    return "uploading";
}
else
{
    return "upload unknown state";
}
或者使用字典将服务状态转换为应用程序状态,或者按照建议使用if-else-if-else

只有两种情况是可能的

if (Youtube_Uploader.fileuploadstatus == "uploading file")
                {
                    Youtube_Uploader.fileuploadstatus = "";
                    return "uploading";
                    //return may happen here case 1
                }
                else
                {
                    return "upload unknown state";
                    // or here case 2
                }
将代码转换为以下内容:

                if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully")
只有两种情况是可能的

if (Youtube_Uploader.fileuploadstatus == "uploading file")
                {
                    Youtube_Uploader.fileuploadstatus = "";
                    return "uploading";
                    //return may happen here case 1
                }
                else
                {
                    return "upload unknown state";
                    // or here case 2
                }
将代码转换为以下内容:

                if (Youtube_Uploader.fileuploadstatus == "file uploaded successfully")

CodeCaster工作得很好。只是一件小事当状态为上传完成时,我想将其重置为默认上载未知状态,因为我每秒都在检查状态,我想一旦状态上载完成,然后立即将其重置为上载未知状态,我的意思是,一旦返回上载完成,则立即执行,然后重置为默认值。@Harim我不确定你在问什么。您可以将其拆分为GetStatusMessagestring uploadStatus和SetStatusMessagestring status方法,然后从要重置状态的位置调用它们。@Harim我想我明白您的意思了。我删除了Youtube_Uploader.fileuploadstatus=;为了简洁起见。我现在在各自的案例下重新添加了它们。CodeCaster它工作得很好。只是一件小事当状态为上传完成时,我想将其重置为默认上载未知状态,因为我每秒都在检查状态,我想一旦状态上载完成,然后立即将其重置为上载未知状态,我的意思是,一旦返回上载完成,则立即执行,然后重置为默认值。@Harim我不确定你在问什么。您可以将其拆分为GetStatusMessagestring uploadStatus和SetStatusMessagestring status方法,然后从要重置状态的位置调用它们。@Harim我想我明白您的意思了。我删除了Youtube_Uploader.fileuploadstatus=;为了简洁起见。我现在将它们重新添加到各自的案例中。