当我在我的代码上运行ReSharper时,例如:
if (some condition)
{
Some code...
}
Run Code Online (Sandbox Code Playgroud)
ReSharper给了我上面的警告(反转"if"声明以减少嵌套),并提出了以下更正:
if (!some condition) return;
Some code...
Run Code Online (Sandbox Code Playgroud)
我想明白为什么那样更好.我一直认为在方法中间使用"返回"有问题,有点像"goto".
我想删除包含数千个文件和文件夹的文件夹.如果我使用Windows资源管理器删除文件夹,则可能需要10-15分钟(并非总是如此,但经常).Windows中有更快的方法来删除文件夹吗?
其他详情:
我正在使用下面的代码删除超过10天的文件.有更简单/更聪明的方法吗?
string source_path = ConfigurationManager.AppSettings["source_path"];
string filename= ConfigurationManager.AppSettings["filename"];
var fileQuery= from file in Directory.GetFiles(source_path,filename,SearchOption.TopDirectoryOnly)
where File.GetCreationTime(file)<System.DateTime.Now.AddDays(-10)
select file;
foreach(var f in fileQuery)
{
File.Delete(f);
}
Run Code Online (Sandbox Code Playgroud)