How to convert long to int in .net?

后端 未结 7 2449
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 15:19

I am developing window phone 7 application in silverlight. I am new to the window phone 7 application. I have the long value in String format as follows

String A         


        
7条回答
  •  南方客
    南方客 (楼主)
    2021-02-18 16:22

    In C# int has 32 bits and long has 64 bits. Therefore not all values of long can be int. Maybe get an array of ints?

    public static int[] ToIntArray(long l)
    {
        var longBytes = BitConverter.GetBytes(l);
    
        // Get integers from the first and the last 4 bytes of long
        return new int[] {
            BitConverter.ToInt32(longBytes, 0),
            BitConverter.ToInt32(longBytes, 4)
        };
    }
    

提交回复
热议问题