添加Lesson16

This commit is contained in:
2025-10-21 20:37:12 +08:00
parent b1d4959956
commit faee796928
7 changed files with 370 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+25
View File
@@ -0,0 +1,25 @@
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进行排序,按照价格从低到高排序
}
}
}