我会赞成其中一个答案 - 他们几乎是正确的.
using (YourService service = new YourService())
{
service.Url = "http://some.other.url/";
// Now you're ready to call your service method
service.SomeUsefulMethod();
}
Run Code Online (Sandbox Code Playgroud)
如果未使用using块,并且抛出异常,则可能会泄漏网络连接等资源.
只需在调用任何服务方法之前设置对象的Url属性:
YourService service = new YourService();
service.Url = "http://some.other.url/";
// Now you're ready to call your service method
service.SomeUsefulMethod();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1433 次 |
最近记录: |