title: C# Equivalent of python3 int.to_bytes
body: <p>I don't want to reinvent the wheel, so is there an equivalent of the <code>int.to_bytes(int,"big")</code> from python3 in C# ?</p>
  
  <p>This is what i would do manually i guess.</p>
  
  <pre><code>private byte[] IntToBytesBig(int number, int len)
          {
              byte[] bytes = BitConverter.GetBytes(number);
              if (BitConverter.IsLittleEndian)                //if little endian, reverse to get big endian
                  Array.Reverse(bytes);
              if (bytes.Length == len) return bytes;          //if already desired length, return.
              if (bytes.Length &gt; len)                         //if length is too long, remove some elements
              {
                  var bytesTmp = Array.Empty&lt;byte&gt;();
                  bytes.CopyTo(bytesTmp, bytes.Length - len);
                  bytes = bytesTmp;
              }
              else                                            //if length is too small, add 0's in byte
              {
                  Array.Reverse(bytes);
                  for (var i = bytes.Length; i &lt; len; i++)
                      bytes[i] =(byte) 0;
                  Array.Reverse(bytes);
              }
              return bytes;
          }
  </code></pre>