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

后端 未结 4 662
臣服心动
臣服心动 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:55

    For example 1 and 2 you need to create static methods:

    public static string InstanceMethod() {return "Hello World";}
    

    Then for example 3 you need an instance of your object to invoke the method:

    object o = new object();
    string s = o.InstanceMethod();
    

提交回复
热议问题