❔ 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?
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?