Automatically create instances according to class names

xiaoxiao2021-03-06  109

private void button1_Click (object sender, System.EventArgs e) {string LoadClassName = "LoadClass.Test"; Type type = Type.GetType (LoadClassName, true); object newInstance = Activator.CreateInstance (type); MessageBox.Show (newInstance. TSTRING ());}} public class test {public test () {} public string getStr () {return "test loadclass.";} Public override string toString () {return "test";}}

转载请注明原文地址:https://www.9cbs.com/read-96998.html

New Post(0)