我想使用的樣本來自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