Files
2025-10-21 20:37:12 +08:00

26 lines
685 B
C#

namespace ConsoleApp1
{
class shopItem
{
public int price;
public shopItem(int price)
{
this.price = price;
}
}
class Program
{
static void Main(string[] args)
{
List<shopItem> shopItems = new List<shopItem>();//创建一个List来存放商店物品
shopItems.Add(new shopItem(3));//往List中添加每个物品的价格
shopItems.Add(new shopItem(1));
shopItems.Add(new shopItem(2));
shopItems.Sort((a, b) => { return a.price > b.price ? 1 : -1; });//使用Sort方法对List进行排序,按照价格从低到高排序
}
}
}