Written in the C # language: Collection Manager

Source: Internet
Author: User

static void Main (string[] args)
{
list<int> numbers = new list<int> ();
while (true)
{
#region Output Collection Contents
Console.WriteLine ("The existing contents of the collection are as follows:");
Console.WriteLine ("===============================");
if (numbers. count==0)
{
Console.WriteLine ("There are no elements in the collection");
}
Else
{
foreach (int item in numbers)
{
Console.Write (item + "\ t");
}
Console.WriteLine ();
}
Console.WriteLine ("===============================");
#endregion
#region the prompt menu and get user-entered menu options
Console.WriteLine ("1. Add data");
Console.WriteLine ("2. Delete data");
Console.WriteLine ("3. Modify data");
Console.WriteLine ("4. Sort in ascending order");
Console.WriteLine ("0. Exit procedure");
Console.Write ("Please Enter (0-4):");
string input = Console.ReadLine ();
#endregion
#region different processing depending on user input
if (input = = "0")
{
Break
}
else if (input = = "1")
{
#region Add Data
Console.Write ("Please enter the number to be added:");
int num = Int. Parse (Console.ReadLine ());
Numbers. ADD (num);
#endregion
}
else if (input = = "2")
{
#region Delete Data
Console.WriteLine ("Clear Enter the data you want to delete (only the first match is deleted):");
int num = Int. Parse (Console.ReadLine ());
Numbers. Remove (num);
#endregion
}
else if (input = = "3")
{
#region Modifying data
if (numbers. Count = = 0)
{
Console.Write ("No program in the collection can be modified, press ENTER to continue");
Console.ReadLine ();
}
Else
{
int maxindex = numbers. Count-1;
Console.Write ("Please enter the subscript to be removed (0-" + Maxindex + ")");
int index = Int. Parse (Console.ReadLine ());
if (Index < 0 | | | index > MAXINDEX)
{
Console.WriteLine ("Input error, subscript out of range, press ENTER to continue");
Console.ReadLine ();
}
Else
{
Console.Write ("Please enter new data:");
int newnum = Int. Parse (Console.ReadLine ());
Numbers[index] = Newnum;
}
}
#endregion
}
else if (input = = "4")
{
#region Ascending sort
for (int i = 0; i < numbers. Count-1; i++)
{
for (int j = i+1; J < numbers. Count; J + +)
{
if (Numbers[i] > Numbers[j])
{
int temp = Numbers[i];
Numbers[i] = Numbers[j];
NUMBERS[J] = temp;
}
}
}
#endregion
}


#endregion
Console Clear Screen
Console.clear ();
}
}

Written in the C # language: Collection Manager

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.