I have the following condition.
Console.WriteLine(Convert.ToChar(65)); // Gives 'A'
Console.WriteLine(Convert.ToChar(65) + 1); // Gives 66; Expectation was 'A1'
Console.WriteLine(Convert.ToChar(65) + "1"); // Gives 'A1'
Why is that? I wanted the 3rd case.
Reason you are getting 66 instead of A1 is because you are adding a char to an integer. If you add a string to char, only then it will return you a string.
documentation on char The char keyword is used to declare an instance of the System.Char structure that the .NET Framework uses to represent a Unicode character. The value of a Char object is a 16-bit numeric (ordinal) value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With