第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

方法參數(shù)內的C#空條件運算符

方法參數(shù)內的C??諚l件運算符

C#
阿晨1998 2021-04-08 18:15:17
我有以下方法:float myMethod(MyObject[][] myList) {      float a = 0;      if (myListProcessingMethod(myList?.Where(x => x.mySatisfiedCondition()).ToList()))      {            a = 5;      }      return a;}bool myListProcessingMethod(List<MyObject[]> myList){      bool isSuccess = false;      if (myList.Any())      {            isSuccess = true;      }      return isSuccess;}我認為這種情況:if (myListProcessingMethod(myList?.Where(x => x.mySatisfiedCondition()).ToList()))我將條件重構為:if (myList?.Length != 0){      if (myListProcessingMethod(myList.Where(x => x.mySatisfiedCondition()).ToList()))      {            a = 5;      }}這兩個條件是否相等?用傳統(tǒng)方式與第一個NullConditionOperator等效的條件是什么?使用NullConditionalOperator進行第二次傳統(tǒng)檢查的等效條件是什么?
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

下面的語句可能會崩潰。如果myList為null,myList?.Length則將為null,并且myList?.Length != 0將為true。這意味著myList.Where可能會因空引用異常而崩潰。


if (myList?.Length != 0)

{

  if (myListProcessingMethod(myList.Where(x => x.mySatisfiedCondition()).ToList()))

  {

        a = 5;

  }

}

你可能想要


if (myList?.Length > 0) 

...

僅當列表不為null且其Length大于0時,它的評估結果才為true。


查看完整回答
反對 回復 2021-04-17
  • 1 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號