Checking if an object is null in C#

前端 未结 18 1868
情深已故
情深已故 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 02:22

      public static bool isnull(object T)
      {
          return T == null ? true : false;
      }
    

    use:

    isnull(object.check.it)
    

    Conditional use:

    isnull(object.check.it) ? DoWhenItsTrue : DoWhenItsFalse;
    

    Update (another way) updated 08/31/2017. Thanks for the comment.

    public static bool isnull(object T)
    {
        return T ? true : false;
    }
    

提交回复
热议问题