string []type =new string[3]{"int","bool","MyNameSpace.MyClass"...}; 这个你不都知道了么。还类型
解决方案 »
- 关于多线程和委托
- 关于链表的用处。。。
- 请教怎样用c++/cli封装c++的code,使其能被c#调用
- vs2003 wap的问题
- ^^^^^^^^^^^^^^@@@@@@@@@ 我遍历文件显示到 listView1中,但读取不了^^^@@@@@@@@@@(附源码)
- OraOps10.dll相关问题,求高手解答
- 谁能告诉我:dataset如何通过网络传输?
- 索引超出了数组界限?如何解决呀
- 求助,关于打印?
- 如何通过C#GetUserDefaultUILangugae获取系统UI显示语言异常?
- 乱码问题。
- 如何让C#中ListBox drawitem事件在我需要的时候才触发,而不是界面刚打开就显示了
object obj = Activator.CreateInstance(t);
Type t1=GetType(myTypeStr[0]);//结果为System.Int32
Type t2=GetType(myTypeStr[1]);//结果为System.Boolean
Type t3=GetType(myTypeStr[2]);//结果为MyNameSpace.MyClass
...求GetType方法。
要求:能够根据“字符串描述”,返回对应的Type。
再判断 swich 判断是否为已知类型 并操作
比如int实际对应的是System.Int32,要一个个写CASE语句吗,.NET有没有什么方法可以直接获取的?switch (typeFullName.ToLower())
{
case "int": typeFullName = "System.Int32"; break;
case "string": typeFullName = "System.String"; break;
case "bool": typeFullName = "System.Boolean"; break;
case "byte": typeFullName = "System.Byte"; break;
case "float": typeFullName = "System.Single"; break;
case "decimal": typeFullName = "System.Decimal"; break;
case "long": typeFullName = "System.Int64"; break;
case "object": typeFullName = "System.Object"; break;
}
返射好像不能用。只能这样,自己把常用的那几中对象加进去, Dictionary<string, Type> dir = new Dictionary<string, Type>();
dir.Add("int", typeof(int));
dir.Add("float", typeof(float));
dir.Add("double", typeof(double));
dir.Add("string", typeof(string)); Type inttype = dir["int"];
Type floatType = dir["float"];
返射好像不能用。只能这样,自己把常用的那几中对象加进去,quote]
不会吧,要自己一个个穷举,那么多怎么穷举,而且还不知道会不会遗漏,没有更好的方法吗?
string []type =new string[3]{"System.Int32","System.Boolean","MyNameSpace.MyClass"...};Type t1=Type.GetType(type [0]);
Type t2=Type.GetType(type [1]);
Type t3=Type.GetType(type [2]);