문제

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