Checking if an object is null in C#

前端 未结 18 1873
情深已故
情深已故 2020-11-28 02:12

I would like to prevent further processing on an object if it is null.

In the following code I check if the object is null by either:

if (!data.Equal         


        
18条回答
  •  伪装坚强ぢ
    2020-11-28 02:43

    I just followed a method that we would usually follow in java script. To convert object to string and then check whether they are null.

    var obj = new Object();
    var objStr = obj.ToString();
    if (!string.IsNullOrEmpty(objStr)){
      // code as per your needs
    }
    

提交回复
热议问题