How do I calculate power-of in C#?

后端 未结 8 1517
别跟我提以往
别跟我提以往 2021-01-01 08:08

I\'m not that great with maths and C# doesn\'t seem to provide a power-of function so I was wondering if anyone knows how I would run a calculation like this:



        
相关标签:
8条回答
  • 2021-01-01 09:13

    For powers of 2:

    var twoToThePowerOf = 1 << yourExponent;
    // eg: 1 << 12 == 4096
    
    0 讨论(0)
  • 2021-01-01 09:15

    The function you want is Math.Pow in System.Math.

    0 讨论(0)
提交回复
热议问题