.NET 简介
.NET 是由微软开发的跨平台、开源开发框架,用于构建各种类型的应用程序,如 Web、桌面、移动、云端和物联网(IoT)等。
🌟 .NET 特性概览
- 跨平台支持(Windows, Linux, macOS)
 - 统一开发平台(Web、API、桌面、移动)
 - 高性能(特别是 ASP.NET Core)
 - 丰富的 IDE 支持(如 Visual Studio、Rider、VS Code)
 - 强类型语言(C#、F#、VB)
 - 原生支持依赖注入(DI)、异步编程、LINQ 查询
 - 与 Azure 无缝集成
 
📌 常见使用场景
- Web API / MVC 网站开发(ASP.NET Core)
 - 桌面软件开发(WPF, WinForms)
 - 微服务架构(搭配 Docker/K8s)
 - 云端无服务器函数(Azure Functions)
 - 控制台/任务调度程序
 - 企业内部系统(ERP、CRM)
 
⚙️ .NET 与 Python 等语言对比
| 特性 | .NET (C#) | Python | 
|---|---|---|
| 类型系统 | 静态类型 | 动态类型 | 
| 性能 | ⭐⭐⭐⭐(原生编译) | ⭐⭐(解释型) | 
| 开发语言 | C#, F#, VB | Python | 
| Web开发 | ASP.NET Core | Django, Flask | 
| 云集成 | Azure 原生支持 | 多云通用 | 
| 学习曲线 | 中等 | 容易入门 | 
| 企业级支持 | 强(微软生态) | 中等 | 
tip
如果你需要构建 高性能 API、企业级系统、Azure 云服务,.NET 是极佳选择。
🚀 示例:ASP.NET Core Web API
dotnet new webapi -n MyApi
cd MyApi
dotnet run
// Controllers/WeatherForecastController.cs
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    [HttpGet]
    public IEnumerable<string> Get() => new[] { "晴天", "阴天", "雨天" };
}
📦 示例:控制台程序
dotnet new console -n HelloApp
cd HelloApp
dotnet run
Console.WriteLine("Hello, .NET World!");
📚 示例:LINQ 查询操作
var numbers = new List<int> { 1, 2, 3, 4, 5 };
var even = numbers.Where(n => n % 2 == 0).ToList();
Console.WriteLine(string.Join(", ", even));  // 输出: 2, 4
🧩 示例:依赖注入服务
builder.Services.AddScoped<IMyService, MyService>();
public interface IMyService {
    string SayHello();
}
public class MyService : IMyService {
    public string SayHello() => "Hello from service";
}
注入使用:
public class HomeController : Controller {
    private readonly IMyService _svc;
    public HomeController(IMyService svc) {
        _svc = svc;
    }
    public IActionResult Index() => Content(_svc.SayHello());
}
✅ 总结
.NET是构建现代化、高性能、跨平台应用的强大框架;- 使用 C# 等强类型语言提高稳定性和安全 性;
 - 原生支持微服务、DI、异步编程、LINQ、Azure;
 - 与 Python 相比更适合大型后端和长期维护项目。