string.Empty vs null.Which one do you use?

前端 未结 5 1923
不思量自难忘°
不思量自难忘° 2020-11-30 23:31

Recently a colleague at work told me not to use string.Empty when setting a string variable but use null as it pollutes the stack?

He says

5条回答
  •  悲哀的现实
    2020-12-01 00:13

    It's been answered to death, but null means no value, not initialized. string.Empty means "" (a blank string) as it is stated on MSDN.

    The safest way to check for an empty or null string is using string.IsNullOrEmpty.

提交回复
热议问题