locked
Method Name Expected RRS feed

  • Question

  • Help! I'm following a tutorial and for some reason, no tutorial works for me. I typed it exactly and I get errors, when it works for the person doing the tutorial. This is what I'm getting right now...

    List<float> whichNote = new List<float> () (1,3,7,4,9,2,4,1,4,3,7,5,8,5,2,7,5,9,6,7,3,5,9,1); Method Name Expected

    the new is the error.

    Can anyone please tell me what I should put to fix this? I'm an absolute beginner...

    Friday, March 30, 2018 5:05 PM

All replies

  • Here you go, rather than use parentheses use {} which is known as an object initializers.  To read about object initializers and other ways to initialize a list see the following page.

    List<float> whichNote = new List<float>(){1, 3, 7, 4, 9, 2, 4, 1, 4, 3, 7, 5, 8, 5, 2, 7, 5, 9, 6, 7, 3, 5, 9, 1};


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites



    Friday, March 30, 2018 5:46 PM
  • Hello,

     I am pleased that we have helpful people. But when those helpful

    people just give out code that corrects the OP issues without the

    "why" then I am not pleased.  OP won't learn this way.   So, please 

    provide the "why" in simple terms or as MSDN Doc ref.

     

    Thanks :)

     

     

    Saturday, March 31, 2018 1:03 PM
  • Hello,

     I am pleased that we have helpful people. But when those helpful

    people just give out code that corrects the OP issues without the

    "why" then I am not pleased.  OP won't learn this way.   So, please 

    provide the "why" in simple terms or as MSDN Doc ref.

     

    Thanks :)

     

     

    I don't know if you have a color screen, but in that case look at the parenthesis which Karen made yellow. 

    Success
    Cor

    Saturday, March 31, 2018 4:17 PM
  • Cor,

     Really? The OP used "(" instead of "{" pairs and you think they

    will know what yellow highlighted means?  The OP most likely

    copy/paste. I am not faulting Karen for the answer but there

    should have been more specific reasoning shown. Otherwise,

    OPs will not "think" but just copy/paste.  This is not a new

    issue in the forums with free code and no reasoning...

     Excuse ME :)

    Saturday, March 31, 2018 9:53 PM
  • Cor,

     Really? The OP used "(" instead of "{" pairs and you think they

    will know what yellow highlighted means?  The OP most likely

    copy/paste. I am not faulting Karen for the answer but there

    should have been more specific reasoning shown. Otherwise,

    OPs will not "think" but just copy/paste.  This is not a new

    issue in the forums with free code and no reasoning...

     Excuse ME :)

    Good point and have modified my response :-)

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, March 31, 2018 10:02 PM
  • Karen,

     Thank you very much! I high doubt OPs read vs snatch

    and grab our code. But, I would like to see them learn

    also.

     Appreciated :)

    Saturday, March 31, 2018 10:25 PM