this post was submitted on 21 Jun 2023
14 points (100.0% liked)

C Sharp

1526 readers
4 users here now

A community about the C# programming language

Getting started

Useful resources

IDEs and code editors

Tools

Rules

Related communities

founded 1 year ago
MODERATORS
 

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);
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 3 points 1 year ago (1 children)

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.

[โ€“] hurp_mcderp 1 points 1 year ago

Also, it's still a tuple so you could simplify existing code without breaking any extension methods you have on them by making a separate type.

It looks like this was added for flexibility and to make the aliasing system more orthogonal to the type rather than to fill a particular need but who knows.