1

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
T. P.
  • 101
  • 1
  • 9
  • 4
    The VB equivalent is `Or`. `Or` will do a bitwise OR of two integral values. And, like C#'s `|`, it will do a non-short-cutting OR operation between two Booleans. And, to be complete, the VB equivalent of C#'s short-cutting OR (`||`) is `OrElse` – Flydog57 Jan 23 '19 at 19:53
  • 3
    [Or Operator](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/or-operator). – Jimi Jan 23 '19 at 19:53
  • 1
    Type into Google “c# to vb converter” – stormCloud Jan 23 '19 at 19:54
  • Why the downvotes, the question seems perfectly legit to me... – Meta-Knight Jan 23 '19 at 20:32
  • @Meta-Knight if I was a betting guy I would say because it's already been answered before here on SO in one form or another, a quick Google search will show exactly the OP what is is etc... – Trevor Jan 23 '19 at 20:49
  • @Çöđěxěŕ: Not that easy to find relevant results by searching for special characters (`|`) or common words (`Or`) in Google, also if it's a duplicate it should be simply closed as duplicate ;-) I couldn't find a duplicate question with a quick search altough I'm sure there is one too. – Meta-Knight Jan 23 '19 at 21:24
  • @Meta-Knight true, but then again you shouldn't just be putting in just that character, you'll get a lot of miss-leads `Is there an equivalent C# pipe in VB.Net?` seems to be more of a question that would have better hits. – Trevor Jan 23 '19 at 21:36

1 Answers1

9

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).

Meta-Knight
  • 17,626
  • 1
  • 48
  • 58
Alexander
  • 9,104
  • 1
  • 17
  • 41