Cannot access a non-static member of outer type via nested type

后端 未结 4 1717
渐次进展
渐次进展 2020-11-30 12:53

I have error

Cannot access a non-static member of outer type \'Project.Neuro\' via nested type \'Project.Neuro.Net\'

with cod

4条回答
  •  不知归路
    2020-11-30 13:44

    you need to instantiate an object of type Neuro somewhere in your code and call OtherMethod on it, since OtherMethod is not a static method. Whether you create this object inside of SomeMethod, or pass it as an argument to it is up to you. Something like:

    // somewhere in the code
    var neuroObject = new Neuro();
    
    // inside SomeMethod()
    int x = neuroObject.OtherMethod();
    

    alternatively, you can make OtherMethod static, which will allow you to call it from SomeMethod as you currently are.

提交回复
热议问题