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

前端 未结 15 2004
长情又很酷
长情又很酷 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 13:56

    When you write

    1 << n
    

    You shift the bit combination 000000001 for n times left and thus put n into the exponent of 2:

    2^n
    

    So

    1 << 10
    

    Really is

    1024
    

    For a list of say 5 items your for will cycle 32 times.

提交回复
热议问题