【发布时间】:2015-09-21 12:19:38
【问题描述】:
所以,我最近正在寻找在 C# 中使用 FTP 的小型库...我通过this 问题到this 类...。
我有点想知道 return 声明在他们所有的 void 方法中的意义......
下面是他们的删除方法:
/* Delete File */
public void delete(string deleteFile)
{
try
{
/* Create an FTP Request */
ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + deleteFile);
/* Log in to the FTP Server with the User Name and Password Provided */
ftpRequest.Credentials = new NetworkCredential(user, pass);
/* When in doubt, use these options */
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
/* Establish Return Communication with the FTP Server */
ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
/* Resource Cleanup */
ftpResponse.Close();
ftpRequest = null;
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
return;
}
我的问题是:
return; 有任何理由或影响吗?
【问题讨论】:
-
return 只是在该行结束函数。如果函数有一个实际的类型返回,那么它会返回一个值(如果指定了一个值)。
-
一般来说,这段代码的风格有问题,在每个方法中都使用
try/catch,并捕获所有可能的异常。我不建议将其用作编码风格的示例。