本文介绍了如何使用C#.net将字符串转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim frm As New Form
Dim formName As String = "Form1"
formName = [Assembly].GetEntryAssembly.GetName.Name & "." & formName
frm = DirectCast([Assembly].GetEntryAssembly.CreateInstance(formName), Form)
frm.Show()
//how to use this in c#
推荐答案
Form frm = new Form();
string formName = "Form1";
formName = string.Format("{0}.{1}", [Assembly].GetEntryAssembly.GetName.Name, formName);
frm = [Assembly].GetEntryAssembly.CreateInstance(formName) as Form;
frm.Show();
或更简洁:
Or more succinctly:
string name = string.Format("{0}.Form1", [Assembly].GetEntryAssembly.GetName.Name);
Form frm = [Assembly].GetEntryAssembly.CreateInstance(formName) as Form;
frm.Show();
string formName = "frmTestForm";
formName = Assembly.GetEntryAssembly().GetName().Name + "." + formName;
Type type = Type.GetType(formName);
Form form = (Form)Activator.CreateInstance(type);
form.StartPosition = FormStartPosition.CenterParent;
form.ShowDialog();
这篇关于如何使用C#.net将字符串转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!