使用sonarqube分析我的代碼并被告知“'actor'在至少一個執行路徑上為空”以下代碼if (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)
{actor.ProducerAgreementIds是一個List<string>。這條語句不是已經在執行空檢查了嗎?或者它應該是:if (actor != null && (actor.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0))
{替代方案將只使用條件訪問if (actor?.ProducerAgreementIds != null && actor.ProducerAgreementIds.Count > 0)適當且不會引起下游問題?謝謝!
- 1 回答
- 0 關注
- 81 瀏覽
添加回答
舉報
0/150
提交
取消