小编3yo*_* af的帖子

如何在C#中扩展数组

我必须使用数组进行练习.用户必须输入3个输入(每次输入有关项目的信息),输入将插入到数组中.然后我必须显示数组.

但是,我很难在不改变其中的信息的情况下增加阵列的长度; 以及如何允许用户输入另一组输入?这是我到目前为止:

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 …
Run Code Online (Sandbox Code Playgroud)

c# arrays input

14
推荐指数
3
解决办法
5万
查看次数

标签 统计

arrays ×1

c# ×1

input ×1