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