+ 2

Why does the addition of two char(char a, char b) equal a number(195)?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { char a = 'a'; char b = 'b'; Console.WriteLine(a); Console.WriteLine(b); Console.WriteLine(a + b); } } }

15th Feb 2017, 7:57 PM
Justin Baker
Justin Baker - avatar
3 odpowiedzi
+ 10
'a' and 'b' in ASCII are 97 and 98, respectively. Trying to add chars adds their ASCII values together. Use Convert.ToChar(a + b) if you want a char result.
15th Feb 2017, 8:09 PM
Tamra
Tamra - avatar
+ 8
yw ^.^
15th Feb 2017, 8:10 PM
Tamra
Tamra - avatar
+ 2
Thank you
15th Feb 2017, 8:10 PM
Justin Baker
Justin Baker - avatar