New features for those who haven’t seen them:

// Primary constructors
public class NamedItem(string name)
{
    public string Name => name;
}

// Default lambda params
var IncrementBy = 
    (int source, int increment = 1) => 
        source + increment;

Console.WriteLine(IncrementBy(5)); // 6
Console.WriteLine(IncrementBy(5, 2)); // 7

// Type aliases
using Point = (int x, int y);
  • Kogasa
    link
    fedilink
    arrow-up
    3
    ·
    1 year ago

    I’m a bit confused about the point of tuple type aliases. I don’t see a good reason to ever use

    using Point = (int x, int y);
    

    over

    record struct Point(int x, int y);
    

    I guess if you’re working with something that expects a tuple or value tuple, this saves you an explicit conversion from your record type to a tuple.