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

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

    Thats bit shifting. Its basically just moving the bits to the left by adding 0's to the right side.

    public enum HttpVerbs {
        Get = 1 << 0,    // 00000001 -> 00000001 = 1
        Post = 1 << 1,   // 00000001 -> 00000010 = 2
        Put = 1 << 2,    // 00000001 -> 00000100 = 4
        Delete = 1 << 3, // 00000001 -> 00001000 = 8
        Head = 1 << 4    // 00000001 -> 00010000 = 16
    }
    

    More info at http://www.blackwasp.co.uk/CSharpShiftOperators.aspx

提交回复
热议问题