添加Lesson16
This commit is contained in:
@@ -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>
|
||||
@@ -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进行排序,按照价格从低到高排序
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user