diff options
author | Martin Costello <martin@martincostello.com> | 2021-06-18 18:04:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-18 18:04:05 +0300 |
commit | 4dcc89eaef2dd1cb95a18bbc66d183cb07fdeb1b (patch) | |
tree | 4b8112c2d578d6682b6a2a131e737908e6551dc8 /src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp | |
parent | df215f26b0f048ee57508655aef957cbc8951ab9 (diff) |
Use Random.Shared (#33213)
Use the new Random.Shared property in the C# Web API template.
Diffstat (limited to 'src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp')
-rw-r--r-- | src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherForecastController.cs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherForecastController.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherForecastController.cs index 2c725ae0a9..b17adf7173 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherForecastController.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherForecastController.cs @@ -68,12 +68,11 @@ namespace Company.WebApplication1.Controllers throw new HttpRequestException($"Invalid status code in the HttpResponseMessage: {response.StatusCode}: {error}"); } - var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] }) .ToArray(); } @@ -94,12 +93,11 @@ namespace Company.WebApplication1.Controllers HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi); var user = await _graphServiceClient.Me.Request().GetAsync(); - var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] }) .ToArray(); } @@ -116,12 +114,11 @@ namespace Company.WebApplication1.Controllers HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi); #endif - var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] }) .ToArray(); } |