int? _Type;
    
 _Type = TypeList.SelectedValue == null?null: Convert.ToInt16(TypeList.SelectedValue);
它说不能<null>隐式转换成<int>
int?不是可空整形吗??为什么不行呢??
那有什么替代方法吗??可以不用逐个If判断,比较简便呢?? 
 
 

解决方案 »

  1.   

    TypeList.SelectedValue你这个是什么类型呢?问题应该出在这里吧?
      

  2.   

    int? _Type = (TypeList.SelectedValue == null) ? null : (int?)Convert.ToInt32(TypeList.SelectedValue);
      

  3.   

    Type = string.IsNullOrEmpty(TypeList.SelectedValue)?null: Convert.ToInt16(TypeList.SelectedValue);
      

  4.   

    ls的 
    int? 这样可以为null
      

  5.   

    int? _Type = (TypeList.SelectedValue == null) ? null : (int?)Convert.ToInt32(TypeList.SelectedValue);
      

  6.   

    _Type = TypeList.SelectedValue == null? default(null): Convert.ToInt16(TypeList.SelectedValue);
      

  7.   

    楼上的全部不对,包括我的,嘿嘿.
    看这里
    _Type = TypeList.SelectedValue == null? default(int?): Convert.ToInt16(TypeList.SelectedValue);
      

  8.   

     default(int?): 还有这样写的啊
      

  9.   

    嗯, 
    对滴,其实就是null。
    我也不明白为什么
    int? value = null; 这样没有问题.
    但是 int? value = (condition)? null:2; 这样就不能通过编译.