What is the difference between (“”) and (null)

前端 未结 9 1199
鱼传尺愫
鱼传尺愫 2021-01-04 18:33

While trying to set Validations i initially encountered some problems with checking if a textbox is null, i tried using

    private void btnGo_Click(object s         


        
相关标签:
9条回答
  • 2021-01-04 19:19

    The difference is that "" means and empty string but null means it doesn't exist

    0 讨论(0)
  • 2021-01-04 19:23

    In layman's term, null means lacking of value and "" mean zero-length string, which is not the same thing. There might be some piece of software that treat null string and "" equally e.g. Console.WriteLine, but it still does not make them the same thing.

    Strictly speaking, "" == null expression is false by design. The equality comparison of String type in .NET framework works by == operator overloading, which does not treat null as equal to "".

    0 讨论(0)
  • 2021-01-04 19:28

    The default value of TextBox.Text is String.Empty or "" not null. So your first code didn't work. null is just to indicate that an object doesn't point to anything, it's not allocated with any memory.

    0 讨论(0)
提交回复
热议问题