1) Definition (MSDN):
The char keyword is used to declare a 16-bit character, used to represent most of the known written languages throught the world.
2) Why char does like numeric types?
A char can be implicitly converted to a numeric type.
A char is closer to an integer than to a string. A string is only a collection of char objects, whereas an integer can present a char and vice versa.
3) Examples
You can simply convert the first of your chars to a string, to outwit your compiler:
var pr = 'R'.ToString() + 'G' + 'B' + 'Y' + 'P';
You could also define a char array and then use the string constructor:
char[] letters = { 'R', 'G', 'B','Y', 'P' };
string alphabet = new string(letters);
If you want to print out a character solely, you always have to convert it to a string, to get its text representation:
var foo1 = 'F';
MessageBox.Show(foo1.ToString());
char
s, since C# doesn't define a built-in + operator for the type. However,char
is implicitly convertible toint
, so the compiler chooses theint
version of the + operator when doing overload resolution. And of course the result of that operator is anotherint
. (Note that "of course" is a bit funny to say, sinceshort
+short
is actually anint
, rather than the "of course" answer of anothershort
!)char
is an integral type in C, and so is in C#. Changing the behaviour of the type without a very good reason (you can create strings from individualchar
s easily using other functionality) would annoy users that had grown accustomed to the C/C++ behaviour.