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.