Search code examples
c#vb.netcode-translation

C# Using With Equivalent in VB.NET


var baseAddress = new Uri("http://www.aaa.com");
    var cookieContainer = new CookieContainer();
    using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer })
    using (var client = new HttpClient(handler){ BaseAddress = baseAddress })
{}

I tried to convert this code with the Developer Fusion tool to VB.NET but was not successful.

Dim baseAddress = New Uri("http://www.aaa.com")
Dim cookieContainer = New CookieContainer()
Using handler = New HttpClientHandler() With { _
    Key .CookieContainer = cookieContainer _
}
    Using client = New HttpClient(handler) With { _
        Key .BaseAddress = baseAddress _
    }
    End Using
End Using

an error occured "key . "

What is the VB.NET equivalent of this code (using with statement)?


Solution

  • Just remove the Key word

    Using handler = New HttpClientHandler() With { _
        .CookieContainer = cookieContainer _
    }
        Using client = New HttpClient(handler) With { _
            .BaseAddress = baseAddress _
        }
        End Using
    End Using