How to check object is null or empty in C#.NET 3.5?

后端 未结 7 1102
悲哀的现实
悲哀的现实 2021-02-15 18:26

If objects contains null or empty then how to validate or check the condition for the same?

How to bool check whether object obj is null or

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 19:12

    Following code could be a safer way of achieving it.

    if(obj != null && !string.IsNullOrEmpty(obj.ToString()))
    {
    
    }
    

    This code saves us from object being a non-string type.

提交回复
热议问题