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