使用sonarqube分析我的代碼并被告知“'actor'在至少一個(gè)執(zhí)行路徑上為空”以下代碼if (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)
{actor.ProducerAgreementIds是一個(gè)List<string>。這條語(yǔ)句不是已經(jīng)在執(zhí)行空檢查了嗎?或者它應(yīng)該是:if (actor != null && (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0))
{替代方案將只使用條件訪問(wèn)if (actor?.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)適當(dāng)且不會(huì)引起下游問(wèn)題?謝謝!
“var”在至少一個(gè)執(zhí)行路徑上為 null - sonarqube
明月笑刀無(wú)情
2022-12-31 09:38:43