2016/06/27

Source: Internet
Author: User

C # Collection Related

. Count//Get the number of collection elements

. Contains ()//Determine if an element exists in the collection

. Sort ()//ascending sort

. Reverse ()//Flip the entire set, collocation. Sort () to enable descending sorting

Set Features:

You do not need to specify the number of elements, the array needs to specify the number. The collection has only one dimension, and the array can be multidimensional.

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Collections;
Using System.Collections.Specialized;

Namespace Collection
{
Class Program
{
static void Main (string[] args)
{
Console.Write ("Please enter the number of people:");
int a = Int. Parse (Console.ReadLine ());
ArrayList x = new ArrayList ();
int sum = 0;
for (int i = 0; i < A; i++)
//{
Console.Write ("Please enter {0} personal score:", i+1);
X.add (int. Parse (Console.ReadLine ()));
sum+= (int) x[i];
//}
X.sort ();
Console.WriteLine ("Average divided into:" +sum/a);
Console.WriteLine ("Maximum:" + (int) x[a-1]);
Console.WriteLine ("Lowest divided into:" + (int) x[0]);
Console.ReadLine ();

Console.Write ("Please enter the number of people:");
int a = Int. Parse (Console.ReadLine ());
ArrayList JH = new ArrayList ();


for (int i = 0; i < A; i++)
//{

Console.WriteLine ("Please enter the first name of {0} person:", i+1);
Jh. ADD (Console.ReadLine ());
Console.WriteLine ("Please enter the age of the person {0}:", i + 1);
Jh. ADD (int. Parse ((Console.ReadLine ()));

//}
for (int i =1; i < a*2; i=i+2)
//{
for (int j = i; j < a*2-2; j=j+2)
// {
if (int. Parse (Jh[i]. ToString ()) <int. Parse (jh[j+2]. ToString ()))
// {
int huan = 0;
Huan = (int) jh[i];
Jh[i] = (int) jh[j+2];
Jh[j+2] = Huan;
String o = "";
o = (string) jh[i-1];
JH[I-1] = jh[j+1];
Jh[j + 1] = O;

// }


// }

//}
int z=0;
int v=1;
for (int i = 0; i < A; i++)
//{
Console.WriteLine ("Name:" +jh[z]);
Console.WriteLine ("Age:" +jh[v]);
Z = z + 2;
v = v + 2;
//}
Console.WriteLine ("Age Max" +jh[0]);
Console.ReadLine ();

foreach (Object aa in JH)//Traversal Collection
//{
//}


Iterating through an array
int[] array = new int[] {2, 3, 4, 5, 6, 7, 8, 9, 2};
foreach (int aa in array)
//{
Console.WriteLine (AA);
//}
Console.ReadLine ();

}
}
}

Written today

2016/06/27

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.