大佬教程收集整理的这篇文章主要介绍了c# – 是否有更可读的方法来制作一长串的\u0026\u0026陈述?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
if(this == that && foo != bar && foo != that && pins != needles && apples != oranges) { DoSomethingInteresTing(); }
通常情况下,如果我被迫做这样的事情,我会将每个语句放在自己的行上,如下所示:
if ( this == that && foo != bar && foo != that && pins != needles && apples != oranges ) { DoSomethingInteresTing(); }
但我仍觉得这有点乱.我很想将if语句的内容重构为它自己的属性
if(canDoSomethingInteresTing) { DoSomethingInteresTing(); }
但是那只是将所有的混乱移动到canDoSomethingInteresTing()并没有真正解决问题.
正如我所说,我的goto解决方案是中间解决方案,因为它不会像最后一个那样模糊逻辑,并且比第一个更具可读性.但必须有更好的方法!
响应Sylon评论的示例
bool canDoSomethingInteresTing { get{ //If these were real values,we Could be more descriptive ;) bool thisIsThat = this == that; bool fooIsntBar = foo != bar; bool fooIsntThat = foo != that; return ( thisIsThat && fooIsntBar && fooIsntThat ); } } if(canDoSomethingInteresTing) { DoSomethingInteresTing(); }
以上是大佬教程为你收集整理的c# – 是否有更可读的方法来制作一长串的\u0026\u0026陈述?全部内容,希望文章能够帮你解决c# – 是否有更可读的方法来制作一长串的\u0026\u0026陈述?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。