define get or set in c#

前端 未结 3 545
迷失自我
迷失自我 2021-01-25 12:57

friends i have problem with using get or set in class in c# when i use get or set in gives error(invalid token { in class) pls, see below code,i have this problem in it

3条回答
  •  执念已碎
    2021-01-25 13:13

    The snippet you have posted is fine as it is, also in regards to the error, as it has the correct number of { to } and in the right order.

    Look at where you have placed it (possibly outside of a class), or look for extra } in the file.

    Update: (following edit in question)

    Your issue is here:

    public int Speed; // <-- ; should not be here
    

    And:

    return _speed // <-- missing the ;
    

    The property should be implemented like this:

    public int Speed
    {
       get
       {
          return _speed;
       }
    }
    

提交回复
热议问题