locked
cannot convert method group 'ToString' to non delegate type 'String'

    Question

  • Hi, i am trying to write a code for the trackbar which when slides changes the value of the respective button which displays the changed value. But i m stuck here with the error tat says "cannot covert method group 'ToString' to non-delegate type 'String'.
    Please help me with this problem and here is my code below:


    private

     

    void TB0_ValueChanged(object sender, EventArgs e)

    {

    Pan0.Text = TB0.Value.ToString;

    SC8_SendPos(nBoardNum, 0,

    short.Parse(TB0.Value.ToString));

    }

    Friday, June 05, 2009 4:25 AM

Answers

  • ToString is a method, so you need to put the parenthesis: TB0.Value.ToString().

    Regards,
    Fernando.

    Keep it Sharp
    • Proposed as answer by Mattias Sjögren Friday, June 05, 2009 6:51 AM
    • Marked as answer by Harry Zhu Thursday, June 11, 2009 8:04 AM
    Friday, June 05, 2009 4:37 AM
  • Hi,
      The error you are getting is becasue of the parenthesis, like Mr Fernando said. Here trackBar.Value is of integer type. Most of time its value will be from 0 to 100, means it can be short mostly. Casting is a bad habit of programming especillay from value type to referance type and vice versa since it affects performance. Here you can convert it like short val=(short)trackBar.Value; It will be efficient that converting it to string and then converting to short(valuetype to referance and then to valuetype).
    -- Thanks Ajith R
    • Marked as answer by Harry Zhu Thursday, June 11, 2009 8:04 AM
    Friday, June 05, 2009 7:10 AM

All replies

  • ToString is a method, so you need to put the parenthesis: TB0.Value.ToString().

    Regards,
    Fernando.

    Keep it Sharp
    • Proposed as answer by Mattias Sjögren Friday, June 05, 2009 6:51 AM
    • Marked as answer by Harry Zhu Thursday, June 11, 2009 8:04 AM
    Friday, June 05, 2009 4:37 AM
  • Hi,
      The error you are getting is becasue of the parenthesis, like Mr Fernando said. Here trackBar.Value is of integer type. Most of time its value will be from 0 to 100, means it can be short mostly. Casting is a bad habit of programming especillay from value type to referance type and vice versa since it affects performance. Here you can convert it like short val=(short)trackBar.Value; It will be efficient that converting it to string and then converting to short(valuetype to referance and then to valuetype).
    -- Thanks Ajith R
    • Marked as answer by Harry Zhu Thursday, June 11, 2009 8:04 AM
    Friday, June 05, 2009 7:10 AM