当前位置: 代码迷 >> ASP.NET >> asp.net中反射有关问题
  详细解决方案

asp.net中反射有关问题

热度:9985   发布时间:2013-02-26 00:00:00.0
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 ";
  相关解决方案