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

前端 未结 15 2005
长情又很酷
长情又很酷 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:11

    That would be the bitwise left shift operator.

    For each shift left, the value is effectively multiplied by 2. So, for example, writing value << 3 will multiply the value by 8.

    What it really does internally is move all of the actual bits of the value left one place. So if you have the value 12 (decimal), in binary that is 00001100; shifting it left one place will turn that into 00011000, or 24.

提交回复
热议问题