C# 将用户输入存储到并行阵列中#

C# 将用户输入存储到并行阵列中#,c#,C#,我试图给用户两个选项,一个是查看数组存储了什么,第二个是输入新项。请帮忙!我曾尝试在方法ItemInfo()中添加数组,但效果不好,我曾尝试在switch中这样做: ItemInfo(itemNArr[itemN],itemNameArr[itemName],itemPriceArr[itemPrice],itemStockArr[itemNStock],itemRatingArr[itemRating] 但仍然不起作用。那么,在这种情况下,我应该如何将用户输入传递到数组并存储它呢!?我会感

我试图给用户两个选项,一个是查看数组存储了什么,第二个是输入新项。请帮忙!我曾尝试在方法ItemInfo()中添加数组,但效果不好,我曾尝试在switch中这样做:

ItemInfo(itemNArr[itemN],itemNameArr[itemName],itemPriceArr[itemPrice],itemStockArr[itemNStock],itemRatingArr[itemRating] 
但仍然不起作用。那么,在这种情况下,我应该如何将用户输入传递到数组并存储它呢!?我会感谢你的帮助

我遇到的问题是:

The name 'itemN' does not exist in the current context line 37
The name 'itemName' does not exist in the current context line 37
The name 'itemPrice' does not exist in the current context line 37
The name 'itemNStock' does not exist in the current context line 37
The name 'itemRating' does not exist in the current context line 37
代码如下:

using System;
using System.Security.Cryptography.X509Certificates;
using static System.Console;
namespace program
    {
        class UseItem
        {
        public static void Main(string[] args)
        {

            int item = AppIntro();
            string[] itemNArr = new string[item];
            string[] itemNameArr = new string[item];
            double[] itemPriceArr = new double[item];
            int[] itemStockArr = new int[item];
            int[] itemRateArr = new int[item];
            // ask to enter price for produect
            for (int i = 0; i < item; i++)
            {
                Clear();
                ItemInfo(i,  out itemNameArr[i], out itemPriceArr[i],  itemStockArr[i],  itemRateArr[i]);
                Clear();
            }
            string ans;
            do
            {
                WriteLine("What would you like to do next?");
                WriteLine(" Enter 1 to display individual course" + " and 2 to add a new product");
                int option = int.Parse(ReadLine());
                int result = int.Parse(ReadLine());
                switch (option)
                {
                    case 1:
                        DisplayItems(itemNArr,itemNameArr,itemPriceArr, itemStockArr, itemRateArr);
                        break;
                    case 2:
                        result = ItemInfo(itemN, itemName,itemPrice,itemNStock,itemRating);
                        break;
                    default:
                        WriteLine("No valid entery was entered. " + "i decided to exit the application.... ");
                        break;
                }
                WriteLine("\n\nWould you like to do another operation?");
                ans = ReadLine();
            } while (ans == "Yes" || ans == "yes");
            WriteLine("\n\nThank you for choosing our application.... coma back again :) ");
        }
            public static int AppIntro()
            {
            WriteLine("Welcome to the PSO App: ");
            WriteLine("You will be asked to enter the product name" + " product price, how many you have in stock of the product" + " and the rate of the product");
            WriteLine("Then you will have a choise to display individual product" + "info");
            WriteLine("\n\nHow many products you want to add!?");
                return int.Parse(ReadLine());
            }
        public static void ItemInfo(int itemN, out string itemName, out double itemPrice, int itemNStock, int itemRating)
        {
            Write(" Enter the item number {0}:", itemN+1);
            itemName = ReadLine();
            Write(" Enter the item name: ");
            itemName = ReadLine();
            Write(" Enter the item price: ");
            itemPrice = double.Parse(ReadLine());
            Write(" Enter the number of the item in stock: ");
            itemNStock = int.Parse(ReadLine());
            Write(" Enter the rate of the item: ");
            itemRating = int.Parse(ReadLine());
        }
        public static void DisplayItems(string[]itemN, string[] itemName, double[] itemPrice, int[] itemNStock, int[] itemRating)
        {
            Write(" Which items would you like to display? Enter it's number: ");
            string valueIn = ReadLine();

            int n = 0;
            for(int i=0; i < itemN.Length; i++)
            {
                if(valueIn == itemN[i])
                {
                    n = i;
                }
                Clear();
                WriteLine("Your item info: ");
                WriteLine("item number is: " + itemN[n]);
                WriteLine("item name is: " + itemName[n]);
                WriteLine(" item price is: " + itemPrice[n]);
                WriteLine(" number of item in the stock is: " + itemNStock[n]);
                WriteLine(" item rate is: " + itemRating[n]);
            }
        }
            }

        }
使用系统;
使用System.Security.Cryptography.X509证书;
使用静态系统控制台;
名称空间程序
{
类UseItem
{
公共静态void Main(字符串[]args)
{
int item=AppIntro();
string[]itemNArr=新字符串[项目];
string[]itemNameArr=新字符串[项目];
double[]itemPriceArr=新的double[项目];
int[]itemStockArr=新int[项目];
int[]itemRateArr=新的int[项目];
//要求输入产品的价格
对于(int i=0;i
我已接近答案,最后我想说,这是我问题的答案

using System;
using System.Security.Cryptography.X509Certificates;
using static System.Console;
namespace program
    {
        class UseItem
        {
        public static void Main(string[] args)
        {
            int n = 0;
            int item = AppIntro();
           
            string[] itemNArr = new string[item];
            string[] itemNameArr = new string[item];
            double[] itemPriceArr = new double[item];
            int[] itemStockArr = new int[item];
            int[] itemRateArr = new int[item];
            // ask to enter price for produect
            //for (int i = 0; i < item; i++)
            //{
            //Clear();
            n = ItemInfo(n, itemNArr, itemNameArr, itemPriceArr, itemStockArr, itemRateArr);
            //Clear();
            //}
            string ans;
            do
            {
               // WriteLine("What would you like to do next?");
                WriteLine(" Enter 1 to display individual course" + " and 2 to add a new product");
                int option = int.Parse(ReadLine());
                //int result = int.Parse(ReadLine());
                
                switch (option)
                {
                    case 1:
                        DisplayItems(itemNArr,itemNameArr,itemPriceArr, itemStockArr, itemRateArr);
                        break;
                    case 2:
                        n = ItemInfo(n, itemNArr, itemNameArr, itemPriceArr, itemStockArr, itemRateArr);
                        break;
                    default:
                        WriteLine("No valid entery was entered. " + "i decided to exit the application.... ");
                        break;
                }
                WriteLine("\n\nWould you like to do another operation?");
                ans = ReadLine();
            } while (ans == "Yes" || ans == "yes");
            WriteLine("\n\nThank you for choosing our application.... come back again :) ");
        }
            public static int AppIntro()
            {
            WriteLine("Welcome to the PSO App: ");
            WriteLine("You will be asked to enter the product name" + " product price, how many you have in stock of the product" + " and the rate of the product");
            WriteLine("Then you will have a choise to display individual product" + "info");
            WriteLine("\n\nHow many products you want to add!?");
            return int.Parse(Console.ReadLine());
            }
        public static int ItemInfo(int n, string[] itemN, string[] itemName, double[] itemPrice, int[] itemNStock, int[] itemRating)
        {


                Write(" Enter the item number:");
            itemN[n] = ReadLine();
                Write(" Enter the item name: ");
            itemName[n] = ReadLine();

            Write(" Enter the item price: ");
            itemPrice[n] = double.Parse(ReadLine());
                Write(" Enter the number of the item in stock: ");
            itemNStock[n] = int.Parse(ReadLine());
                Write(" Enter the rate of the item: ");
            itemRating[n] = int.Parse(ReadLine());
            n++;
            return n;
        }
        public static void DisplayItems(string[]itemN, string[] itemName, double[] itemPrice, int[] itemNStock, int[] itemRating)
        {
            Write(" Which items would you like to display? Enter it's number: ");
            string valueIn = ReadLine();

            int n = 0;
            for(int i=0; i < itemN.Length; i++)
            {
                if(valueIn == itemN[i])
                {
                    n = i;
                }
                Clear();
                WriteLine("Your item info: ");
                WriteLine("item number is: " + itemN[n]);
                WriteLine("item name is: " + itemName[n]);
                WriteLine(" item price is: " + itemPrice[n]);
                WriteLine(" number of item in the stock is: " + itemNStock[n]);
                WriteLine(" item rate is: " + itemRating[n]);
            }
        }
            }

        }
    
使用系统;
使用System.Security.Cryptography.X509证书;
使用静态系统控制台;
名称空间程序
{
类UseItem
{
公共静态void Main(字符串[]args)
{
int n=0;
int item=AppIntro();
string[]itemNArr=新字符串[项目];
string[]itemNameArr=新字符串[项目];
double[]itemPriceArr=新的double[项目];
int[]itemStockArr=新int[项目];
int[]itemRateArr=新的int[项目];
//要求输入产品的价格
//对于(int i=0;i