-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
In the templates of ASP.NET Core Web API, the Get() method of 'aspnetcore/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Controllers/WeatherForecastController.cs ' is as follows:
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}The return value of Get() method is of IEnumerable, and the Select() method returns the same type, so there was no need to convert it to an array using ToArray().
Furthermore, it can cause huge memory consumption problem, and I have stated it in a post: https://www.reddit.com/r/aspnetcore/comments/z7jk8r/who_says_net_doesnt_have_gc_tuning_changing_one/
Describe the solution you'd like
I suggest that remove the invocation of 'ToArray()', which could set up a better model for .NET developers.
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels