Example of list in c #

Source: Internet
Author: User

Protected void Page_Load (object sender, EventArgs e) {List
 
  
StudentNames = new List
  
   
(); StudentNames. add ("John"); studentNames. add ("Mary"); studentNames. add ("Rose"); // display each element foreach (string item in studentNames) {Response. write (item); Response. write ("
   
");} Response. Write ("

"); // Convert the List to string studentAllName = string. join (",", studentNames. toArray (); Response. write (studentAllName); Response. write ("

"); List StudentScore = new List (); StudentScore. add (100); studentScore. add (98); studentScore. add (59); // sort studentScore. sort (); // reverse Sort studentScore. reverse (); // display each element foreach (decimal score in studentScore) {Response. write (score); Response. write ("
");} // Total SUM Response. Write (" total score "+ studentScore. Sum (); Response. Write ("
"); // List whether there is Response. Write (studentScore. Exists (MatchPRE); Response. Write ("

"); // Convert List to JSon List List = new List (); For (int I = 0; I <5; I ++) {Student a = new Student ();. name = "Zhang San" + I;. age = I;. sex = "male"; list. add (a);} string json = new System. web. script. serialization. javaScriptSerializer (). serialize (list); Response. write (json); Response. write ("

");} Private static bool MatchPRE (decimal p) // condition matching function. Each element in list1 will be input to P. // after matching, the function returns {if (p = 100) // This sentence is a matching condition. If a match is returned, you can change it to the desired value return true; else {return false ;}} public struct Student {public string Name; public int Age; public string Sex ;}

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.