我正在使用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