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

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

    Its (<<) a bitwise left shift operator, it moves the bit values of a binary object. The left operand specifies the value to be shifted and the right operand specifies the number of positions that the bits in the value are to be shifted.

    In your case if the value of list.count is 4 then loop will run till i < (1<< 4) which is 16 (00010000)

    00000001 << 4 = 00010000(16)

提交回复
热议问题