tags:

views:

96

answers:

5
MessageBox.Show((some_string.Length).ToString);

I am getting two errors for this:

  1. The best overloaded method match for 'System.Windows.Forms.MessageBox.Show(string)'

  2. Argument '1': cannot convert from 'method group' to 'string'

Can someone tell me how to do this correctly?

+5  A: 
MessageBox.Show((some_string.Length).ToString());
Jason W
You need the brackets for the ToString function
Jason W
+1  A: 
MessageBox.Show((some_string.Length()).ToString());
Cătălin Pitiș
+3  A: 

Functions need brackets when they are called, you are missing () at the end of ToString

MessageBox.Show((some_string.Length).ToString());

The errors:

Error 1 The best overloaded method match for 'System.Windows.Forms.MessageBox.Show(string)'

This is just saying that it is expecting a string (MessageBox.Show()), and you did not provide it with one.

Error 2 Argument '1': cannot convert from 'method group' to 'string'

This is saying that you cannot convert a method group (ToString without brackets to make it a function call) as a string parameter in the required method.

Kyle Rozendo
+1  A: 

in you example you have forgotten the parenthesis:

MessageBox.Show((some_string.Length).ToString());
PierrOz
+1  A: 

You have to know that, ToString is not a property, but a method.

So you must use a pair of parenthesis.

MessageBox.Show((some_string.Length).ToString());
JMSA