質問

I try to compare string variable with string - out parameter and it isn't compiled . It's seem it wait to initialization before compare but i can't change the value before .

public bool DownloadZipFile(out string zipUrl)
{
        string zip = System.Windows.Forms.Clipboard.GetText();
        // my code ...

        if (zipUrl != string.Empty && zipUrl == zip)
            Assert.Fail("Copy Zip Url : zip url not updated . zip url equal to prev zip url");

        zipUrl = zip;
        return true;
}

When I build the proj I get :

Error 2 Use of unassigned out parameter 'zipUrl'

役に立ちましたか?

解決

out parameters are expected to be passed into method as uninitialized references and initialized before leaving the function. Given that, in your code you are trying to compare an uninitialized variable, thats why you get compilation error.

Could you try with ref?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top