我想使用的样本来自This SO article。如何在C#IF语句中使用“return”这个例子?
public static bool HasWritePermissionOnDir(string path)
{
var writeAllow = false;
var writeDeny = false;
var accessControlList = Directory.GetAccessControl(path);
if (accessControlList == null)
return false;
var accessRules = accessControlList.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier));
if (accessRules == null)
return false;
foreach (FileSystemAccessRule rule in accessRules)
{
if ((FileSystemRights.Write & rule.FileSystemRights) != FileSystemRights.Write) continue;
if (rule.AccessControlType == AccessControlType.Allow)
writeAllow = true;
else if (rule.AccessControlType == AccessControlType.Deny)
writeDeny = true;
}
return writeAllow && !writeDeny;
}
我如何使用 “返回writeAllow & &!writeDeny” 在if语句?或者我甚至可以这样做。对不起,如果这是一个愚蠢的问题,但在我有限的经验,我没有看到这样的回报。
你没见过的关键字'return'后跟体现在哪里? '返回1 + 2;'看起来更熟悉吗?这是同一件事。 – 2012-02-14 22:18:06
或更好。 'return true && false;' – 2012-02-14 22:20:27