문제

I'm using the following code in my program, would I still need to call response.close()? Or does the FtpWebResponse IDisposable implementation close the response?

using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{

}

So basically, would I need to do this?

using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
    response.close();
}
도움이 되었습니까?

해결책

No you don't have to call Close, since Dispose already does that. FtpWebResponse is inherited from WebResponse and it has explicitly implemented Dispose, which internally call Close.

Code for WebResponse.cs from : http://www.dotnetframework.org/default.aspx/4@0/4@0/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Net/System/Net/WebResponse@cs/1305376/WebResponse@cs

 /// <internalonly>
        void IDisposable.Dispose() {
            try
            {
                Close();
                OnDispose();
            }
            catch { }
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top