假设 从文本框获得一个值
string name = txtName.text;
然后定义了个泛型集合
Dictionary<string,BodyCheckItem> "这里可以用name做动态变量名吗"
= new Dictionary<string,BodyCheckItem>();
string name = txtName.text;
然后定义了个泛型集合
Dictionary<string,BodyCheckItem> "这里可以用name做动态变量名吗"
= new Dictionary<string,BodyCheckItem>();
解决方案 »
- oracle表里的数据总是被锁!急急急
- 【MapX】【在线等】MapX中鼠标碰到图中符号或者图元时的事件是什么?
- C# 在wince5.0下面实现flash播放
- COM+服务的自动事务处理大家帮我看看
- .net remoting HTTP
- 怎样在gridview中把相就的列设置为超级链接?
- 求助:关于文件下载问题?
- 在C#里怎么实现颜色反显问题?
- 这样不行吗????
- 能否得到SharePoint Team Services中各登录用户的的信息,如用户名、用户权限
- string[] 转成 byte[] 求赐教!
- 无法将类型“int”隐式转换为“System.Data.SqlClient.SqlDataReader”?怎么解决?
name就成了 name,name1,name2.......
{
FieldInfo fi=this.GetType().GetField("a"+wl
,BindingFlags.NonPublic|BindingFlags.Instance
);
if(fi==null)
throw(new Exception("cant find a"+wl));
if(fi.FieldType!=typeof(int))
throw(new Exception("type unmatched"));
return (int)fi.GetValue(this);
}
using System;
using System.Reflection;
namespace XX
{
class Class1
{
int bc=100;
int abc=1000;
public int getValue(string wl)
{
FieldInfo fi=this.GetType().GetField("a"+wl
,BindingFlags.NonPublic|BindingFlags.Instance
);
if(fi==null)
throw(new Exception("cant find a"+wl));
if(fi.FieldType!=typeof(int))
throw(new Exception("type unmatched"));
return (int)fi.GetValue(this);
}
public void Run()
{
Console.Write(this.getValue("bc"));
}
}
class XX
{
[STAThread]
static void Main(string[] args)
{
new Class1().Run();
}
}
}
动态生成类
参考这里:http://dotnet.chinaitlab.com/CSharp/745310.html