adding chars
-
char a = 'A';
char b = 'B';a = a + b; //error
a += b; //OKI thought they r both exactly the same thing. Can someone tell me whats the difference.Pl.
-
char a = 'A';
char b = 'B';a = a + b; //error
a += b; //OKI thought they r both exactly the same thing. Can someone tell me whats the difference.Pl.
i think... a = a + b; is trying to assign a string (a + b) to a char (a) where as.. a += b; is taking them to be int values and adding 65 + 66 (ASCII values) and setting a to be 131 Atleast this is my understading
My opinion is... If someone has already posted an answer, dont post the SAME answer
-
i think... a = a + b; is trying to assign a string (a + b) to a char (a) where as.. a += b; is taking them to be int values and adding 65 + 66 (ASCII values) and setting a to be 131 Atleast this is my understading
My opinion is... If someone has already posted an answer, dont post the SAME answer
-
char a = 'A';
char b = 'B';a = a + b; //error
a += b; //OKI thought they r both exactly the same thing. Can someone tell me whats the difference.Pl.
The meaning of + operator depends on the types added together. "A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type" For chars the + is adding the integers together that are used for representing a single char. So in your first line the result is an int. The second line contains automatically assignment so the result type cannot change (since you don't have an intermediate result) thus the operation results to a char. In the line having an error you must do casting explicitely to the intermediate result.
The need to optimize rises from a bad design.My articles[^]
-
The meaning of + operator depends on the types added together. "A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type" For chars the + is adding the integers together that are used for representing a single char. So in your first line the result is an int. The second line contains automatically assignment so the result type cannot change (since you don't have an intermediate result) thus the operation results to a char. In the line having an error you must do casting explicitely to the intermediate result.
The need to optimize rises from a bad design.My articles[^]
Thanx, that makes sense
-
Thanx, that makes sense