Greyed out my codes of null checking before invoking a delegate

蹲街弑〆低调 提交于 2019-12-02 03:19:57

Before invoking a delegate, I did a null check. However the codes are greyed out. Does it mean the grey codes are not effective just like comments?

It means that the Visual Studio pre-compiler/design-time-compiler detects the statement is most likely not needed.

If so what should I do to prevent invoking a null delegate?

Nothing, the compiler will still determine at compile time (and actually at run-time as well) if the statement is needed.

I've just heard that grey codes in VS will still be compiled. The null check is still effective. So this is not a problem at all.

IDE makes it grey to suggest that there's simpler formats, which is the null condition operator in my case. However it should not give such suggestion here, just ignore it would be fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!