1. List Extension

Source: Internet
Author: User

Preface

Three extension methods of List

1. Processing extension methods in () Format

2. Process extension methods that match the SelectListItem type (SelectListItem type is the type to be used in the drop-down box)

3. Further extension of the Distinct method (if the value in the list is an object, Distinct cannot filter through the fields in the object, which can be implemented after extension)

Operation

The first step is to provide an extension method in two formats: integer and string.

 











 











Step 2: Expand the method and implementation, and then define a List. The Code is as follows:











String strAge = age. ToStringList (); // usage of the Extension Method ToStringList
Var name = list. Select (c => c. Name );
String strName = name. ToStringList (); // usage of the Extension Method ToStringList

 

 

{
Return reusltItems. Select (c => new SelectListItem
{
Value = valueProperty (c). ToString (),
Text = textProperty (c ),
}). ToList ();
}

 

 















Step 2: implement the extension method. The Code is as follows:

 





Step 3: implement the Code as follows:

 

In actual development, the extension method is simple, fast, and standard. It is worth accumulating in development.

 

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.