【发布时间】:2015-02-04 04:50:59
【问题描述】:
为什么
int? nullInt = null;
base.Response.Data = (new BusinessLogic.RefDataManager(base.AppSettingsInfo)).SelectAppData(new DC.AppData() { AppDataKey = app_data_key != string.Empty ? app_data_key : null, AppDataTypeId = app_data_type_id != string.Empty ? int.Parse(app_data_type_id) : nullInt });
编译,但是这个
base.Response.Data = (new BusinessLogic.RefDataManager(base.AppSettingsInfo)).SelectAppData(new DC.AppData() { AppDataKey = app_data_key != string.Empty ? app_data_key : null, AppDataTypeId = app_data_type_id != string.Empty ? int.Parse(app_data_type_id) : null});
没有?第二条语句的编译错误是“无法确定条件表达式的类型,因为'int'和null之间没有隐式转换”
DC.AppData 是
public class AppData
{
[DataMember(Name = "AppDataKey")]
public string AppDataKey { get; set; }
[DataMember(Name = "AppDataTypeId")]
public int? AppDataTypeId { get; set; }
}
【问题讨论】:
-
为什么要把所有这些都塞在一行上,如果你只使用多行,它会更具可读性,而且你不会遇到这样的问题。