Search code examples
c#vb.netpipeoperator-keywordequivalent

Is there an equivalent of C#´s | operator in VB.Net?


Is there an equivalent of the C#'s pipe operator (|) in VB.Net?

I have some code from here How to grant full permission to a file created by my application for ALL users?

It is in C# and i want to convert it to VB.Net. I am at this point so far (VS says there is an error: | 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

Solution

  • The equivalent is Or.

    InheritanceFlags.ObjectInherit Or InheritanceFlags.ContainerInherit
    

    It will perform bitwise "or" operation between operands.

    For example if you have the following enumeration

    C#:

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

    VB:

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

    The result of Values.Odd | Values.Even (Values.Odd Or Values.Even) is Values.All. This is because Odd = 1 is 01 in binary representation and Even = 2 is 10 and 01 or 10 equals 11 which is 3 (All).