What's new

C#. Pa check naman po ng code ko. About List.

G I N E B R A

Forum Expert
Elite
Joined
Nov 18, 2017
Posts
6,076
Reaction
5,966
Points
2,078
Age
23
List<string> myList = new List<string>();
string[] letters = { "X", "C", "O", "M", "P", "U", "T", "E", "R", "S" };
//0-1-2-3-4-5-6-7-8-9

Console.WriteLine("=o=o=o=MENU=o=o=o=");
Console.WriteLine("[1] - ADD AN ELEMENT");
Console.WriteLine("[2] - REMOVE AN ELEMENT");
Console.WriteLine("[3] - CONVERT");
Console.WriteLine("[4] - EXIT");

while (true)
{
Console.Write("\nENTER YOUR CHOICE: ");
int choice = Convert.ToInt32(Console.ReadLine());

if (choice > 4)
{
Console.WriteLine("PLEASE ENTER A VALID CHOICE");
}

else
{
//ADD AN ELEMENT // CHOICE 1
if (choice == 1)
{
Console.Write("\nINPUT A NUMBER: ");
int elementalChoice = Convert.ToInt32(Console.ReadLine());
myList.Add(letters[elementalChoice]);
//foreach (var displayRequirement in myList)
//{
// Console.Write("ELEMENT: "+displayRequirement+"\n");
//}
}

//REMOVE AN ELEMENT // CHOICE 2
else if (choice == 2)
{
int currentIndexNumbers = myList.Count();
if (currentIndexNumbers == 0)
{
currentIndexNumbers = 0;
}
else
{
currentIndexNumbers = currentIndexNumbers - 1;

}
Console.WriteLine("SELECT AN INDEX BETWEEN 0 AND " + currentIndexNumbers+": ");
int removeIndex = Convert.ToInt32(Console.ReadLine());
myList.RemoveAt(removeIndex);
//foreach (var displayRequirement in myList)
//{
// Console.Write("ELEMENT: " + displayRequirement + "\n");
//}
}

//CONVERT
else if (choice == 3)
{

//Ikaw na dito haha

}

else
{
break;
}



Paano po kaya mag Convert? Eto po nasa pic ang example.
 

Attachments

Similar threads

Back
Top