有时在安全和害怕之间只有一线之隔。
这段代码是否越界进入了吓人的区域?
DuckbillPlatypusForm dbpf = null;
if (radioButtonUseExistingPlatypus.Checked) {
dbpf = new DuckbillPlatypusForm(DuckbillSetupUtils.DuckbillPlatypusState.Readonly, funnyMammalIDs);
} else if (radioButtonCreateNewFromExistingPlatypus.Checked) {
dbpf = new DuckbillPlatypusForm(DuckbillSetupUtils.DuckbillPlatypusState.Template, funnyMammalIDs);
} else if (radioButtonCreateNewPlatypus.Checked) {
dbpf = new DuckbillPlatypusForm(DuckbillSetupUtils.DuckbillPlatypusState.StartNew, funnyMammalIDs);
}
if (null != dbpf)
{
dbpf.Show();
}
毕竟单选按钮只有三个,并且在设计时检查了一个,所以 dbpf 永远不能为空,对吧?除非以某种方式在设计时所有单选按钮都未选中,或者我添加了另一个单选按钮而不更新此代码,并且该单选按钮被选中,但是在什么时候我只是“咬紧牙关”并接受类似的风险?