我正在使用c#語言並在基於控制檯的應用程序上執行此操作。我遇到的問題是按字母順序排序。我自己添加產品和數量,因此沒有固定的數組列表。我想知道如何根據我進入控制檯進行排序。這是否有意義?我會在哪裏輸入代碼來執行此操作?我已經嘗試,因爲你可以看到我在這裏突出顯示它。但它會出現錯誤,如{「指定的投射無效」}和「當從一個數字投射時,該值必須小於無窮大。在C#中對ArrayList進行排序#
編輯:程序現在只顯示說明和價格,我試圖讓它也顯示數量。我試圖輸入「int q」,然後quantity = q,但我得到「Error 2 Type'TheosVendingMachine.Merchandise'的錯誤已經定義了一個名爲'Merchandise'的成員參數類型!
public string getDescription()
{
return this.description;
}
public double getPrice()
{
return this.price;
}
public int getQuantity()
{
return this.quantity;
}
//a simple constructor
public Merchandise(string n, double id)
* { description = n; price = id; }*
// a simple ToString, always good to have around!
public override string ToString()
{ return description + " (£ " + price + ")" + quantity; }
public class Merchandise
{
private string description;
private double price;
public Merchandise(string aDescription, double aPrice)
{
this.description = aDescription;
this.price = aPrice;
}
public string getDescription()
{
return this.description;
}
public double getPrice()
{
return this.price;
}
public override bool Equals(object other)
{
bool result;
if (other == null)
{
result = false;
}
else
{
Merchandise merchandise = (Merchandise)other;
result = (this.description.Equals(merchandise.description) && this.price == merchandise.price);
}
return result;
}
public override string ToString()
{
return this.description + " at £ " + this.price;
}
}
}
爲什麼地球上你首先使用'ArrayList'? 'List'是.NET 2.0中的替代品,'ArrayList'在很長一段時間內一直處於「不使用」列表中。 –
BradleyDotNET
2014-12-03 18:15:17
因爲我對這個原諒我很陌生,所以我這樣做是爲了課程,講師是在1000年後,所以這是我所能獲得的所有幫助。 – NoobCoder 2014-12-03 18:16:00
你可以在這個問題上增加一段話,說明你實際上想要做什麼?這會讓我們知道你想要完成什麼,並讓我們能夠更好地指引你朝着正確的方向前進。 – 2014-12-03 18:16:59