// 这是一个简单的 C# Web API 示例代码,使用 ASP.NET Core 框架。
// 该示例创建了一个基本的 HTTP GET 端点,返回一个字符串。
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
// GET 请求:/WeatherForecast
[HttpGet]
public string Get()
{
return "Hello, World!";
}
}
}
WeatherForecastController
是一个控制器类,继承自 ControllerBase
。它处理来自客户端的 HTTP 请求。[ApiController]
和 [Route("[controller]")]
属性用于定义 API 控制器和 URL 路由。[HttpGet]
属性表示这是一个处理 HTTP GET 请求的方法。当用户访问 /WeatherForecast
路径时,会调用 Get()
方法并返回字符串 "Hello, World!"
。上一篇:c#字符串转int
下一篇:c# directory
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站