int? Position_ID;Position_ID = string.IsNullOrEmpty(pid) ? null : int.Parse(pid);这样编译时候出错:Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'int'如何解决?

解决方案 »

  1.   

    Position_ID = string.IsNullOrEmpty(pid) ? 0 : int.Parse(pid); 
      

  2.   

    string为空时不能转int的
    可以用2楼的方法赋0值给Position_ID
      

  3.   

     Nullable<int> Position_ID; 
     
      

  4.   

    Position_ID是要插入数据库的,
    不能赋0
      

  5.   

    string str ="0";
    int i;
    i=int.parse(str);
      

  6.   

    Position_ID = string.IsNullOrEmpty(pid) ? null : (int?)int.Parse(pid);
      

  7.   

    这是三元操作符的问题
    可以参考下
    http://msdn2.microsoft.com/en-us/library/aa691313(VS.71).aspx你可以把代码写成如下int? Position_ID = null;
    if (!String.IsNullOrEmpty(pid))
    {
        int.TryParse(pid, out Position_ID);
    }
      

  8.   

    哦,Sorry,TryParse有问题
    还是像楼上那样转一下吧~~