I wan't to convert a int to a char, but I don't want the (char)int
method, because (char)3
won't give '3'
but ''
.
So, there's a built-in way to get what I want, or I need to make it myself?
I wan't to convert a int to a char, but I don't want the (char)int
method, because (char)3
won't give '3'
but ''
.
So, there's a built-in way to get what I want, or I need to make it myself?
I think this is the easiest, most readable way:
(char)('0' + 3)
If you want to be more culture aware, you can use this.
CultureInfo.CurrentCulture.NumberFormat.NativeDigits[3]
(char)('0' + IntegerValue)
Note: you use 3 so your integer value is 3 you can write 3 instead of integer value
Just as an alternative, from earlier comments (with special thanks to @recursive):
int yourInt = 3; //can be double or decimal as well
char val = yourInt.ToString()[0];
Although it takes the first digit, it will work for other numeric types as well (double, decimal, ...).