You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
807 B
C#
33 lines
807 B
C#
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
var summaries = new[]
|
|
{
|
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
};
|
|
|
|
app.MapGet("/weatherforecast", () =>
|
|
{
|
|
var forecast = Enumerable.Range(1, 5).Select(index =>
|
|
new WeatherForecast
|
|
(
|
|
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
Random.Shared.Next(-20, 55),
|
|
summaries[Random.Shared.Next(summaries.Length)]
|
|
))
|
|
.ToArray();
|
|
return forecast;
|
|
});
|
|
|
|
app.Run();
|
|
|
|
internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
|
{
|
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
}
|