1、通过全局变量
2、通过构造函数传递参数
3、通过委托实现
通过委托例子:WebForm1 向Class1传递参数值:
//
{
public partial class WebForm1 : System.Web.UI.Page
{
//step1.声明一个委托
public delegate void DoSomethingEventHandler(string s1);
protected void Page_Load(object sender, EventArgs e)
{
//step2.通过委托调用其它类中的方法
DoSomethingEventHandler myDelegate = new DoSomethingEventHandler(Class1.DoSomething);
//step3.实现向其它类传递参数值
myDelegate("去吧");
}
}
}
//
public class Class1
{
private static string OperValue = string.Empty;
//接受代理传来参数的方法
public static void DoSomething(string s1)
{
OperValue = s1;
}
}