What does | (pipe) mean in c#?

前端 未结 6 1065
鱼传尺愫
鱼传尺愫 2020-12-03 17:23

Just wondering what the pipe means in this? ive never seen it before:

FileSystemAccessRule fullPermissions = new FileSystemAccessRule(
             \"Network         


        
6条回答
  •  被撕碎了的回忆
    2020-12-03 17:56

    For an enum marked with the [Flags] attribute the vertical bar means 'and', i.e. add the given values together.

    Edit: This is a bitwise '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 a bitwise-OR but semantically you think of it as an AND!

提交回复
热议问题