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] 5 points 1 year ago* (last edited 1 year ago) (1 children)

In my opinion type aliases shouldn't use using keyword, since it is used by other useful features, but overall those changes are nice.

Yes, C# is slowly getting more bloated, like C++, but it's still a lot better than cpp imo and those changes (especially primary constructors) can remove boilerplate code.

[โ€“] Perhyte 5 points 1 year ago

Type aliases already existed, and already used the using keyword. This version essentially just adds a few new options for the bit after the = (to be specific: tuple types, array types, pointer types, or other unsafe types).