例如:
public class a
{
b b1=new b();
public void a1()
{
MessageBox.Show("a1");
}
//如何将A1函数传递给B类中,并且在B类中执行A1这个函数
}public class b
{
.......
}在这里先谢谢大家了!
public class a
{
b b1=new b();
public void a1()
{
MessageBox.Show("a1");
}
//如何将A1函数传递给B类中,并且在B类中执行A1这个函数
}public class b
{
.......
}在这里先谢谢大家了!
public class a
{
b b1=new b(() => a1());
public void a1()
{
MessageBox.Show("a1");
}public class b
{
public b(Action func) { func(); }
}
public class a
{
b b1=new b(() => a1());
public void a1()
{
MessageBox.Show("a1");
}public class b
{
public b(Action func) { func(); }
}
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();
}
}