Initial commit: C# 学习笔记和示例代码
- Lesson 01-10: C# 基础语法 - WebView2: 集成示例 - notes/: 详细笔记
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,96 @@
|
||||
using System;
|
||||
|
||||
namespace Lesson03
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// ========== if / else ==========
|
||||
Console.WriteLine("=== if / else ===");
|
||||
int score = 85;
|
||||
|
||||
if (score >= 90)
|
||||
{
|
||||
Console.WriteLine("优秀");
|
||||
}
|
||||
else if (score >= 60)
|
||||
{
|
||||
Console.WriteLine("及格");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("不及格");
|
||||
}
|
||||
|
||||
// 三元运算符
|
||||
string result = score >= 60 ? "及格" : "不及格";
|
||||
Console.WriteLine($"三元运算: {result}");
|
||||
|
||||
// ========== switch ==========
|
||||
Console.WriteLine("\n=== switch ===");
|
||||
int day = 3;
|
||||
|
||||
switch (day)
|
||||
{
|
||||
case 1:
|
||||
Console.WriteLine("星期一");
|
||||
break;
|
||||
case 2:
|
||||
Console.WriteLine("星期二");
|
||||
break;
|
||||
case 3:
|
||||
Console.WriteLine("星期三");
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("其他");
|
||||
break;
|
||||
}
|
||||
|
||||
// ========== for 循环 ==========
|
||||
Console.WriteLine("\n=== for 循环 ===");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Console.WriteLine($"计数: {i}");
|
||||
}
|
||||
|
||||
// ========== foreach ==========
|
||||
Console.WriteLine("\n=== foreach 循环 ===");
|
||||
string[] names = { "无言势", "VRChat", "字幕" };
|
||||
|
||||
foreach (string name in names)
|
||||
{
|
||||
Console.WriteLine(name);
|
||||
}
|
||||
|
||||
// ========== while 循环 ==========
|
||||
Console.WriteLine("\n=== while 循环 ===");
|
||||
int count = 0;
|
||||
while (count < 3)
|
||||
{
|
||||
Console.WriteLine($"while: {count}");
|
||||
count++;
|
||||
}
|
||||
|
||||
// ========== do while ==========
|
||||
Console.WriteLine("\n=== do while ===");
|
||||
int n = 0;
|
||||
do
|
||||
{
|
||||
Console.WriteLine($"do while: {n}");
|
||||
n++;
|
||||
} while (n < 3);
|
||||
|
||||
// ========== break 和 continue ==========
|
||||
Console.WriteLine("\n=== break 和 continue ===");
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
if (i == 3) continue; // 跳过 3
|
||||
if (i == 7) break; // 退出循环
|
||||
Console.WriteLine(i);
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user