入力パラメーターのないパブリック メソッドを持つクラスが 1 つあります。
public partial class MyClass: System.Web.UI.MasterPage
{
public void HelloWorld() {
Console.WriteLine("Hello World ");
}
}
HelloWorld()
メソッドを別のクラスに呼び出したい
public partial class ProductType_Showpt : System.Web.UI.Page
{
protected void ChkChanged_Click(object sender, EventArgs e)
{
MyClass master =(MyClass) this.Master;
master.GetType().GetMethod("HelloWorld").Invoke(null, null);
}
}
しかし、それはこの例外をスローします
Object reference not set to an instance of an object.