Search code examples
c#typescasting

in c# how to convert an var to a char array. char array[8]


in c# how to convert an varto a char array. char[8] array I can guarantee this var is not too big.

such as, I have

var a = 634711440648369988;

and I want char[8] c store it.

How to do this conversion correctly? Thanks.


Solution

  • You can just cast it to a string and use the ToCharArray method.

    char [ ] c = a.ToString().ToCharArray();