三目 運算符
<表達式1>?<表達式2>:<表達式3>; "?"運算符的含義是: 先求表達式1的值, 如果為真, 則執行表達式2,並返回表達式2的結果 ; 如果表達式1的值為假, 則執行表達式3 ,並返回表達式3的結果. 例1: int a=2; int c=3; int b=(a>c)?2:3; 輸出b; 這樣的結果是b為3 例2:
分頁 排序問題 OrderByCount 排序字段
OrderByColumn((OrderByCount == "" ? "sendDate" : OrderByCount + " desc,sendDate")), OrderBy.Desc,
引申:雙目 < null>?<表達式2> null??""即:前者 為null 轉化成后者,后者可以隨意取值。此例將null 轉化為空"".
例如:
string lessonID =
(HQLHelper.ExecuteScalar("select lessonpreparId from home_lessonprepar where lessonProcess='" + ho.LessonProcess + "' and step='2'") ?? "").ToString();
ExecuteScalar():若返回為Null,再tospring()報錯,所以使用 ??
