+ 4

Please tell me guys. Why do we have to convert an int to a string in c# in these type of situations?

static void Main(string [ ] args) { int mark; mark = Convert.ToInt32(Console.Readline());

28th Dec 2017, 1:34 PM
primex
primex - avatar
5 Answers
+ 6
@AndreasK thank u šŸ˜Š
28th Dec 2017, 1:43 PM
primex
primex - avatar
+ 2
The console.Readline() method reads the line and returns the lines value as String. This is why you have to convert the return value to an integer if you want to store it in one.
28th Dec 2017, 1:41 PM
Andreas K
Andreas K - avatar
+ 1
int is value type & string is a reference type convert value type to reference type go 2 incompatible data conversion string smarks=Convert.Tostring(marks);
28th Dec 2017, 8:08 PM
Harish Revankar
Harish Revankar - avatar
+ 1
Doesnā€™t C# have promotion? Just print it with marks+ā€ā€
21st Mar 2018, 2:23 AM
Boris Clark
Boris Clark - avatar
0
string smarks=Convert.Tostring(marks);
30th Dec 2017, 10:06 PM
Brian Saguay
Brian Saguay - avatar