問題是: 編寫一個程序,將數據讀入int類型的數組。有效的輸入是從0到10.你的程序應該確定輸入了多少個值。輸出不同條目的列表以及該條目發生次數的計數。關於C#作業問題,請
我到目前爲止有:
using System;
using System.Collections;
namespace ConsoleApplication25
{
class Program
{
static void Main()
{
ArrayList list = new ArrayList();
string inValue;
Console.WriteLine("Please enter a value from 0-10");
Console.WriteLine("To end the program, type 11");
for (int i = 0; i < 11; i++)
{
Console.Write("Enter Value:", i);
inValue = Console.ReadLine();
i = int.Parse(inValue);
list.Add(i);
list.Remove(11);
list.Sort();
}
int[] c = list.ToArray(typeof(int)) as int[];
foreach (int value in c)
{
Console.WriteLine(value);
}
Console.WriteLine("There are {0} values.", list.Count);
}
}
}
當我被困在正在顯示的每個值的計數。我已經嘗試設置一個如果與一個櫃檯,並設置案件休息和不成功。我們還沒有開始使用LINQ。任何建議或提示將不勝感激。
感謝,
傑森
Ixnay在'ArrayList'。這是一個棄用的類(僅爲向後兼容提供),現在已經被新的通用集合完全替代了6年。 – 2010-11-20 23:01:21
@Ben福格特:沒有,'ArrayList'類實際上沒有過時。它實際上已經過時,但仍未標記爲過時(出於某種原因)。 – Guffa 2010-11-20 23:07:59
@Guffa:無論哪種方式,它不應該在新的代碼中使用了,誰教它,應立即停用並送刷上自己的技能任何教授。 .NET 2.0和泛型是在2005年11月發佈的(所以僅在五年前,並非如我所說的那樣,但測試版在10個月前已公開可用,已足夠接近六年),但仍然沒有任何藉口'ArrayList'。 – 2010-11-21 00:56:43