Why can't I call a public method in another class?

后端 未结 4 669
臣服心动
臣服心动 2021-02-05 22:27

I have got these two classes interacting and I am trying to call four different classes from class one for use in class two.

The methods are public and they do return va

4条回答
  •  名媛妹妹
    2021-02-05 22:37

    It sounds like you're not instantiating your class. That's the primary reason I get the "an object reference is required" error.

    MyClass myClass = new MyClass();
    

    once you've added that line you can then call your method

    myClass.myMethod();
    

    Also, are all of your classes in the same namespace? When I was first learning c# this was a common tripping point for me.

提交回复
热议问题