2011-05-16 45 views
1

我已經要求用戶輸入金額,但我正努力將它們存儲到一個數組中。這是我迄今爲止所做的。請幫助。我是一名初學者。我想從用戶那裏得到所需的整數數量並將它們存儲到一個數組中

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      int intNum; 

      Console.WriteLine("How many integers must be stored in the program?"); 
      intNum = Convert.ToInt32(Console.ReadLine()); 

     } 

    } 
} 

回答

5

好了,下一步可能是創建數組(假設你真的想用一個數組;它很容易在這種情況下做的,但你也可以考慮使用List<int>要求你事先知道尺寸)。

然後你需要循環intNum次,每次向用戶詢問一個數字,解析它,並將它存儲在數組中。

這是幾個小步驟。我不會給你完整的代碼,但是如果你展示了你的進展情況,以及哪一步導致了你的問題,我們可以嘗試進一步幫助你。

相關問題