I don't like this… Is this cheating the language?

前端 未结 15 2661
一向
一向 2021-02-13 15:52

I have seen something like the following a couple times... and I hate it. Is this basically \'cheating\' the language? Or.. would you consider this to be \'ok\' because the IsNu

15条回答
  •  情歌与酒
    2021-02-13 16:12

    A bit off topic but if you rand the same example in vb.net like this

    dim someString as string
    someString = MagicFunction()
    if not string.IsNullOrEmpty(someString) and someString.Length > 3 then
        ' normal string, do whatever
    else
        ' do someting else
    end if
    

    this would go bang on a null (nothing) string but in VB.Net you code it as follows do do the same in C#

    dim someString as string
    someString = MagicFunction()
    if not string.IsNullOrEmpty(someString) andalso someString.Length > 3 then
        ' normal string, do whatever
    else
        ' do someting else
    end if
    

    adding the andalso make it behave the same way, also it reads better. as someone who does both vb and c' development the second vb one show that the login is slighty different and therefor easyer to explain to someone that there is a differeance etc.

    Drux

提交回复
热议问题