LINQ brainstorm 001 _ Aggregate functions

Source: Internet
Author: User

Max ()
Min ()
Average average ()
Total count ()
Sum ()

1. Entity Bean

Public ClassTuzi {Public IntId {Get;Set;}Public IntAge {Get;Set;}Public StringName {Get;Set;}}

2. Object Initiator

   Static List <Tuzi>Inittuziinfo () {list <Tuzi> tuzilist = New List <Tuzi> {  New Tuzi {name = "  Tuzi001  " , Age = 10  },  New Tuzi {name = "  Tuzi002  " , Age = 24 },  New Tuzi {name = "  Tuzi003  " , Age = 33  },  New Tuzi {name = "  Tuzi004  " , Age = 47  },  New Tuzi {name = " Tuzi005  " , Age = 59  },  New Tuzi {name = "  Tuzi006  " , Age = 65  },  New Tuzi {name = "  Tuzi007  " , Age = 76 },  New Tuzi {name = "  Tuzi008  " , Age = 80  }};  Return  Tuzilist ;} 

3. Results

 

  Static   Void Main ( String  [] ARGs) {list <Tuzi> tuzilist = Inittuziinfo ();  # Region 001 Aggregate functions Int Maxage = ( From S In  Tuzilist  Select S). Max (A => A. Age); console. writeline (  "  The largest age is:  " + Maxage );  // Lambda form              Int Minage = tuzilist. Select (A => A. Age). Min ();  //  ==> Edit  //  Minage = tuzilist. Select <Tuzi, int> (delegate (Tuzi T)  //  {  //  Return T. Age;  //  }). Min (); Console. writeline ( " The minimum age is:  " + Minage );  Int Avgage = ( Int ) Tuzilist. Select (A => A. Age). Average (); console. writeline (  "  Average age:  " + Avgage); avgage = ( Int ) Tuzilist. Where (A => A. Age! = Maxage & A. Age! = Minage). Average (A => A. Age); console. writeline ( "  The removal is the highest, and the average age after the lowest is:  " + Avgage );  Int Agecount = ( Int ) Tuzilist. Select (A => A. Age). Count (); console. writeline (  "  Total Age:  " + Agecount );  Int Agesum = ( Int ) Tuzilist. Select (A =>A. Age). sum (); console. writeline (  "  Age:  " + Agesum );  # Endregion   Console. readkey ();} 

 

 

 

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.