开发者

Why can I not do a Messagebox.Show(some_int)?

开发者 https://www.devze.com 2022-12-26 12:56 出处:网络
MessageBox.Show((some_string.Le开发者_JAVA技巧ngth).ToString); I am getting two errors for this: The best overloaded method match for \'System.Windows.Forms.MessageBox.Show(string)\'
MessageBox.Show((some_string.Le开发者_JAVA技巧ngth).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?


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


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.


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


in you example you have forgotten the parenthesis:

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


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());
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号