List (t) Implementation object operations, find findall contains foreach sort

Source: Internet
Author: User

Object class:

News publication entity
[Mapto ( " Us_news " )]
Public   Abstract   Class Newsbll
{
[Mapto ( " FID " )]
Public   Abstract   String Id { Get ;}
///   <Summary>
/// Title
///   </Summary>
[Mapto ( " Fcaption " )]
Public   Abstract   String Caption { Get ; Set ;}
///   <Summary>
/// News category PK-ss_Item.ID
///   </Summary>
[Mapto ( " FTYPE " )]
[Manytoone (localkey =   " FTYPE " , Foreignkey =   " FID " )]
Public   Abstract Dictitembll type { Get ; Set ;}
///   <Summary>
/// News content
///   </Summary>
[Mapto ( " Fcontent " )]
Public   Abstract   String Content { Get ; Set ;}
///   <Summary>
/// Publisher
///   </Summary>
[Mapto ( " Fuserid " )]
Public   Abstract   String Userid { Get ; Set ;}
}
News category
[Mapto ( " Ss_item " )]
Public   Abstract   Class Dictitembll
{

[Mapto ("FID")]
Public Abstract IntId {Get;}

///   <Summary>
/// Group ID
///   </Summary>
[Mapto ( " Fclassid " )]
Public   Abstract   Int Classid { Get ; Set ;}
///   <Summary>
/// Parent node ID
///   </Summary>
[Mapto ( " Fparentid " )]
Public   Abstract   Int Parentid { Get ; Set ;}
///   <Summary>
/// Dictionary name
///   </Summary>
[Mapto ( " Fname " )]
Public   Abstract   String Name { Get ; Set ;}

# Endregion

}

1. Use Find to search for a single matching Value

 

Newsbll news = List. Find ( Delegate (Newsbll X)
{
Return X. type. ID =   10001 ; // Search for a single object with ID = 10001 in the category (type) Sub-object in the News list
});

2. Use findall to search for Multiple matching values.

List < Newsbll > Newslist = List. Find ( Delegate (Newsbll X)
{
Return X. type. ID =   10001 ; // Search for multiple objects with ID = 10001 in the category (type) Sub-object in the News list
});

3. Check whether the value meeting the condition exists using contains

 

Bool Iscontains = List. Find ( Delegate (Newsbll X)
{
Return X. type. ID =   10001   && X. userid = " Ejiyuan " ; // Search for the id = 10001 in the subobject of category (type) in the News list, and whether the publisher is ejiyuan.
});

4. Use foreach to operate on each list object

 

List. Find ( Delegate (Newsbll X)
{
X. Caption =   " 10001 " ; // Change all titles in the list to 10001

});

5. sort by sort and by category ID

List. Sort ( Delegate (Newsbll X, documentbll y)
{
If (X. type. ID < Y. type. ID)
{
Return   - 1 ;
}
Else   If (X. type. ID = Y. type. ID)
{
Return   0 ;
}
Else   Return   1 ;
});

 

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.