Checks whether the object is null or empty

Source: Internet
Author: User

Whether it's in WinForm development, or in ASP. When you get data from a data source, you never know the state of the data, and you always have to judge her, but every time you make a judgment, you always write a bunch of code.
Time is long, always feel not very good, so there is the following code encapsulation, this is an extended generic method, written in the system. Under the namespace, omit the time to write so much code, each time as long as the origin of the call to the following.

Oh

1 namespaceSystem2 {3      Public Static classCheckvalueexten4     {5         /// <summary>6         ///checks whether the current object is null, or string is Nullorempty7         /// </summary>8         /// <typeparam name= "T" ></typeparam>9         /// <param name= "str" ></param>Ten         /// <returns></returns> One          Public Static BOOLCheckvalue<t> ( ThisT str) A         { -             if(str is string) -             { the                 if(!string. IsNullOrEmpty (str. ToString ())) -                 { -                     return true; -                 } +                 Else -                 { +                     return false; A                 } at             } -             Else -             { -                 if(str = =NULL) -                 { -                     return false; in                 } -                 Else to                 { +                     return true; -                 } the             } *         } $     }Panax Notoginseng}
Source Code

Checks whether the object is null or empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.