访问方法 类

Accessing methods been classes

这是一个非常愚蠢的问题,但我如何访问其他 类 的方法。我发现由于静态引用问题,我无法像 java 那样在 类 之间传递对象。在我的研究中,我找到了我认为可能有用的方法的委托,例如 Objective C,但我要么不了解它们是如何工作的,要么它们与我的问题无关。我也看过 ref 但这似乎也无济于事,但我对此的理解也是有限的。这就是我想要做的事情。

class foo
{
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false); 
        Application.Run(new frmMainWindow());
    }

     public void callSomeMethod(Para)
     {
         //call someMethod from foo class - this step is my problem
     }
}

class bar
{
    public static bar()
    {
        //init
    }

    public void someMethod(para1, para2)
    {
        // bar.someMethod calls foo.CallSomeMethod
        callSomeMethod(Para);
    }
}

我知道这是一个基本问题,但我很困惑。我花了几个小时在网上摆弄和搜索。我知道我缺少一些基本的东西...

谢谢

希望这段代码是自描述的。这是一个简单的控制台应用程序,虽然不能解决您的确切问题,但您应该能够看到 类 是如何相互作用的,并且您希望能够从这里设计出适合您的问题。

public class Foo
{
    static void Main(string[] args)
    {
        //new instance of Bar
        var bar = new Bar();

        //call method defined on Bar
        bar.SomeMethod("Hey", "There");
    }

    public static void MethodFromFoo(string param1, string param2)
    {
        Console.WriteLine(param1 + ' ' + param2);
        Console.ReadLine();
    }
}

public class Bar
{
    public void SomeMethod(string param1, string param2)
    {
        // call method on Foo -- no need for new instance (static)
        Foo.MethodFromFoo(param1, param2);
    }
}

这是一个经常犯的简单错误

namespace WindowsFormsApplication1
{
class foo
{

    static void Main(string[] args)  // Initial Solution
    {
           Application.EnableVisualStyles();
           " 
               "
    }

     public void callSomeMethod( r )
     {
          //call someMethod from foo class - this step is my problem
     }
}


class bar  
{

      public static bar()
      {
           //init
      }
       public void someMethod(r1 r2)
       {
           Console.WriteLine("r1: {0}",  r2.get());
           Console.ReadKey();   // Similar To Getch(); in C [ Hold The Answer ]
       }
}

让我知道这是否有效?