I have to do an exercise using arrays.
The user must enter 3 input (each time, information about items) and the inputs will be inserted in the array
Then i must to display the array.
The difficulty i face is that i don't know how to increase the array's length without changing the information within it and how to allow the user to enter another information again?
public string stockNum;
public string itemName;
public string price;
string[] items = new string[3];
public string [] addItem(string[] items)
{
System.Console.WriteLine("Please Sir Enter the stock number");
stockNum = Console.ReadLine();
items.SetValue(stockNum, 0);
System.Console.WriteLine("Please Sir Enter the price");
price = Console.ReadLine();
items.SetValue(price, 1);
System.Console.WriteLine("Please Sir Enter the item name");
itemName = Console.ReadLine();
items.SetValue(itemName, 2);
Array.Sort(items);
return items;
}
public void ShowItem()
{
addItem(items);
Console.WriteLine("The stock Number is " + items[0]);
Console.WriteLine("The Item name is " + items[2]);
Console.WriteLine("The price " + items[1]);
}
static void Main(string[] args)
{
DepartmentStore depart = new DepartmentStore();
string[] ar = new string[3];
// depart.addItem(ar);
depart.ShowItem();
}
How can i allow the user to enter more than on input of information .. for example, the first time the user will enter the information about item ( socket number, price and name) .. how can i make the user enter another information about other item ?
hHow can i display the socket num, price and name for each item in the array, if i suppose to have more than one item in the array ?