C# topic for methods contains mistake | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C# topic for methods contains mistake

As you can see in the example, void Print(int a) { Console.WriteLine("Value: "+a); } The + operator is used to concatenate values. In this case, the value of a is joined to the text "Value: ". You will get an error because "a" is integer, not string!

28th Sep 2016, 10:10 AM
Dmitry Nekrasov
Dmitry Nekrasov - avatar
1 Answer
0
(1) Here '+' is overloaded to string concatenation (automatically). (2) Each character printed on Console is typecasted to string, So "a" is int type but when it's value is getting printed on Console screen the value of "a" is treated as "String" not as "Integer".
30th Sep 2016, 7:23 PM
Priyank Namdev
Priyank Namdev - avatar