© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
Decabytes

❔ Class method construction using lambda?

I was looking at some Avalonia code and I noticed this code
internal class Database
{
public IEnumerable<TodoItem> Get
public IEnumerable<TodoItem> GetItems() => new[]
{
new TodoItem{Description = "Walk the dog" },
new TodoItem{Description = "Buy some milk"},
new TodoItem{Description = "Learn Avalonia", isChecked = true }
};

I'm confused about the => new[] part. If the method had just been
public IEnumerable<TodoItem> GetItems()
{
new TodoItem{Description = "Walk the dog" },
new TodoItem{Description = "Buy some milk"},
new TodoItem{Description = "Learn Avalonia", isChecked = true }
};

I wouldn't have batted an eye. Does => new[] just mean collect the results in a curly brace into an array? What is this feature called?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Using method in other class
C#CC# / help
3y ago
Lambda or extension method reference [Answered]
C#CC# / help
4y ago
❔ generic class in generic method
C#CC# / help
3y ago