[ACCEPTED]-What does | (pipe) mean in c#?-c#
For an enum marked with the [Flags] attribute 5 the vertical bar means 'and', i.e. add the 4 given values together.
Edit: This is a bitwise 3 'or' (though semantically 'and'), e.g.:
[Flags]
public enum Days
{
Sunday = 0x01,
Monday = 0x02,
Tuesday = 0x04,
Wednesday = 0x08,
Thursday = 0x10,
Friday = 0x20,
Saturday = 0x40,
}
// equals = 2 + 4 + 8 + 16 + 32 = 62
Days weekdays = Days.Monday | Days.Tuesday | Days.Wednesday | Days.Thursday | Days.Friday;
It's 2 a bitwise-OR but semantically you think 1 of it as an AND!
It is normally a bitwise or operator. In this context, it's 1 used on an enum with the flags attribute set.
It's a bitwise OR of two values, presumably 2 it creates a FileAccessRule with both FullAccess 1 and Modify permissions set.
It's a binary operator:
Binary | operators are predefined 6 for the integral types and bool. For integral 5 types, | computes the bitwise OR of its 4 operands. For bool operands, | computes 3 the logical OR of its operands; that is, the 2 result is false if and only if both its 1 operands are false.
I'm assuming you mean this: FileSystemRights.FullControl | FileSystemRights.Modify
This FileSystemRights, is 13 an enum with FullControl and Modify having 12 their own numeric values.
So if FullControl 11 = 1 and Modify = 2,
FileSystemRights.FullControl | FileSystemRights.Modify = 3.
00000001 | 00000010 = 00000011.
Each bit is a "flag" for 10 the method. The input checks to see which 9 "flag" is set and what to do.
So 8 in this example, position 1 (the digit all 7 the way on the right in this case) is FullControl, and 6 position 2 is Modify. The method looks 5 at each of the positions, and changes it 4 behavior. Using flags is a way of passing 3 in multiple parameters of behaviors without 2 having to create a parameter for each possiblity 1 (e.g. bool allowFullControl, bool allowModify) etc.
It's a boolean or. FullControl and Modify 3 represent bits in a mask. For example 0001 2 and 0101. If you would combine those via 1 pipe, you would get 0101.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.