VB.net中如果定义Object对象如:Dim obj As Object
可以用如下方法obj.Value获取对象的Value,但C#没有Value这方法,怎么转成等价的语句呢?
在线等~谢谢

解决方案 »

  1.   

    C#里Object类就有限的四个方法,
    一般情况下,我们都要用转换函数将Object类转换成具体的类型,
    再进行操作的
      

  2.   

    C#要用反射:object obj = YourRefObject;
    System.Reflection.PropertyInfo pi = obj.GetType().GetProperty("Value");
    return pi.GetValue(obj, null);
      

  3.   

    To:3tzjq 
    pi.GetValue(obj, null)返回的这个是什么类型啊
      

  4.   

    To:3tzjq  Dim cookie As Object = CurrentContext.Request.Cookies(CookieName())
                        If (Not cookie Is Nothing AndAlso cookie.Value <> "") Then这段代码~加颜色部分整成C#是啥样的啊,谢谢
      

  5.   

    貌似楼主还没解决。
    Dim cookie As Object = CurrentContext.Request.Cookies(CookieName()) 
    if cookie Is Nothing then return ...dim value as object = cookie.GetType().GetProperty("Value").GetValue(cookie, nothing)
    if value is nothing then value = string.emptyIf string.isnullorempty(value.ToString())=false Then 
    ...