例如:
public class a
{
b b1=new b();
public void a1()
{
MessageBox.Show("a1");
}

//如何将A1函数传递给B类中,并且在B类中执行A1这个函数
}public class b
{
.......
}在这里先谢谢大家了!

解决方案 »

  1.   

    使用委托
    public class a
    {
    b b1=new b(() => a1());
    public void a1()
    {
    MessageBox.Show("a1");
    }public class b
    {
        public b(Action func) { func(); }
    }
      

  2.   

    你应该多去看看委托
    public class a
    {
    b b1=new b(() => a1());
    public void a1()
    {
    MessageBox.Show("a1");
    }public class b
    {
        public b(Action func) { func(); }
    }
      

  3.   

    针对LZ的需求有两种方法:
    1:将a中的a1定义成静态的,b中直接调用即可    public class a
        {
            b b1 = new b();
            public static void a1()
            {
                MessageBox.Show("a1");
            }        //如何将A1函数传递给B类中,并且在B类中执行A1这个函数
        }    public class b
        {
            public static void Test()
            {
                //这里直接调用
                a.a1();
            }
        }2:使用委托    public class a
        {
            b b1 = new b();
            public void a1()
            {
                MessageBox.Show("a1");
            }        //如何将A1函数传递给B类中,并且在B类中执行A1这个函数
        }    public class b
        {        public void TestOther()
            {
                Action action = new a().a1;
                action();
            }
        }