读书人

asp.net中反射有关问题

发布时间: 2011-12-30 23:30:45 作者: rapoo

asp.net中反射问题!
public class index : System.Web.UI.Page
{
protected string i12= "asdf ";
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Type typ1=typeof(index);
object ss=typ1.GetField( "i12 ").GetValue(this);
Response.Write(ss.ToString());

}
}
}

这样会抱错,如要实现使用反射取得i12的值。怎么操作。谢谢


[解决办法]
string v = "123 ";


Type type = v.GetType();

MethodInfo info = type.GetMethod( "ToString ", new Type[0]);

Response.Write(info.Invoke(v,null).ToString());

[解决办法]
public string i12 = "asdf ";

读书人网 >asp.net

热点推荐