Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't values implicitly convertible to string in C#?

I have some code like:

int value = 5;
MessageBox.Show ( value );

and the MessageBox.Show complains saying:

"cannot convert from 'int' to 'string'"

I seem to remember some cases where values seem to be implicitly converted to string values, but can't recall them exactly.

What's the reason behind this decision that any value isn't implicitly convertible to string values?

like image 818
Joan Venge Avatar asked Apr 01 '11 17:04

Joan Venge


1 Answers

MessageBox.Show() only accepts a string. When you use something like Debug.WriteLine, it accepts a bunch of different object types, including object, and then calls ToString() on that object. This is probably what you're experiencing.

like image 76
Mike Park Avatar answered Nov 15 '22 20:11

Mike Park