C # create your own extension method,

Source: Internet
Author: User

C # create your own extension method,

C # you can create your own Extension Method:

Refer to this http://www.cnblogs.com/insus/p/8004097.html to determine whether it is empty and then assign value

In the preceding three methods, the keyword null appears. When judging, You Need To = null or! = Null.

In fact, you can create a C # extension method to eliminate this complexity.

 

 

Public static class ExtensionMethod {public static bool IsNull (this object obj) {return obj = null;} public static bool IsNotNull (this object obj) {return obj! = Null;} Source Code


Therefore, Method 5 can be generated in the previous article:


 

Result = str. IsNull ()? "": Str; result = str. IsNotNull ()? Str: ""; Source Code

 

Related Article

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.