是否有C#的等价物| VB.Net中的运营商?

时间:2019-01-23 19:50:19

标签: c# vb.net pipe operator-keyword equivalent

VB.Net中是否有C#的管道运算符(|)的等效项?

我在这里有一些代码How to grant full permission to a file created by my application for ALL users?

它在C#中,我想将其转换为VB.Net。我到目前为止(VS说有错误:| InheritanceFlags.ContainerInherit):

Sub ZugriffsrechteEinstellen()

    Dim dInfo As New DirectoryInfo(strPfadSpracheINI)
    Dim dSecurity As New DirectorySecurity

    dSecurity = dInfo.GetAccessControl()
    dSecurity.AddAccessRule(New FileSystemAccessRule(New SecurityIdentifier(WellKnownSidType.WorldSid, Nothing), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow))

    dInfo.SetAccessControl(dSecurity)

End Sub

1 个答案:

答案 0 :(得分:7)

等效为Or

InheritanceFlags.ObjectInherit Or InheritanceFlags.ContainerInherit

它将在操作数之间执行按位“或”运算。

例如,如果您具有以下枚举

C#:

enum Values
{
    None = 0,
    Odd = 1,
    Even = 2,
    All = 3
}

VB:

Enum Values
    None = 0
    Odd = 1
    Even = 2
    All = 3
End Enum

Values.Odd | Values.EvenValues.Odd Or Values.Even)的结果为Values.All。这是因为Odd = 1是二进制形式的01,而Even = 210,并且01 or 10等于11,即3 (All)。 / p>