我在C#中创建了一个函数:
private void customShow(Form someForm, Type formType) {
if (someForm == null || someForm.IsDisposed) someForm = (Form)Activator.CreateInstance(formType);
someForm.StartPosition = FormStartPosition.CenterScreen;
someForm.MdiParent = this;
someForm.Show();
someForm.WindowState = FormWindowState.Maximized;
}
Run Code Online (Sandbox Code Playgroud)
然后我想这样做:
private void mnuKategori_Click(object sender, EventArgs e) {
customShow(frmKategori, typeof(Master.FrmKategori));
frmKategori.isCRUD = true;
}
Run Code Online (Sandbox Code Playgroud)
它在方法的第二行失败,因为变量frmKategori在方法执行后仍为null.如果我将"someForm"参数引用到引用中,它也会失败,因为看起来C#不支持带有"ref"和"out"关键字的多态性.有没有人对此提出建议?在此先感谢您的回复.
c# ×1