C# equivalent to Java 8 “method reference”

You would have to declare a method outside of Thing (or a static Thing method), then you could pass a method-group reference to it:

private string GetName(Thing thing)
{
    return thing.Name;
}

...

List<String> nameList1 = thingList.Select(GetName).ToList();

In C# 6, you can also use an expression-bodied function to save a couple of lines:

private string GetName(Thing thing) => thing.Name;

Leave a Comment