加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

vb.net – 如何避免… else和切换案例

发布时间:2020-12-17 00:28:46 所属栏目:大数据 来源:网络整理
导读:我已经编程了很多时间.一般来说,我在一些语言中编程,如 PHP,ASP.net,Java,JavaScript等.在所有语言中,我必须使用大量的if else语句.喜欢如果value = 10那么…如果我审查我的代码,那么我找到很多的条件.所以我想尽量减少他们,但如何不确定. 有一点是使用类最
我已经编程了很多时间.一般来说,我在一些语言中编程,如 PHP,ASP.net,Java,JavaScript等.在所有语言中,我必须使用大量的if else语句.喜欢如果value = 10那么…如果我审查我的代码,那么我找到很多的条件.所以我想尽量减少他们,但如何不确定.

有一点是使用类最小化,但仍然更多…

像任务,猫,秒和类型:

if task = 'add' then
   if cat = "animal" then
      if sec = "man" then
          if type = "male" then
                 'do the following stuffs
          else
                 'do the following stuffs
          end if
      elseif sec = "horse" then
          if type = "run"
                 'do the following stuffs
          else
                 'do the following stuffs
          end if
      elseif....
      end if
   elseif cat = "plant" then
     if sec = "land" then
          if type="tree" then
                 'do the following stuffs
          elseif type = "grass" then..
                 'do the following stuffs
          elseif...
          end if
    elseif sec = "water" then
    ...
...

更多n更继续n继续

所以想知道如何最小化它们并编写一些有效的代码?

对不起,最近通知任务,秒和类型可能有很多值.我的if语句嵌套嵌套.

更多的解释我的代码也看起来像:

http://thedailywtf.com/Articles/Coding-Like-the-Tour-de-France.aspx

许多if..else语句通常是 Polymorphism未被使用的症状.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读