What do two left-angle brackets “<<” mean in C#?

前端 未结 15 2007
长情又很酷
长情又很酷 2020-12-12 13:55

Basically the questions in the title. I\'m looking at the MVC 2 source code:

[Flags]
public enum HttpVerbs {
    Get = 1 << 0,
    Post = 1 << 1,         


        
15条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 14:13

    That's the left bitshift operator. It shifts the bit pattern of the left operand to the left by the number of binary digits specified in the right operand.

    Get = 1 << 0, // 1
    Post = 1 << 1, // 2
    Put = 1 << 2,  // 4
    Delete = 1 << 3, // 8
    Head = 1 << 4  // 16
    

    This is semantically equivalent to lOperand * Math.Pow(2, rOperand)

提交回复
热议问题