Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

edit: I should have read further. The more interesting parts happen very late in the article. A lot of what is described is still possible (including the querying) in C#, but other things only in very awkward ways.

Original post follows:

It seems this is almost possible in C#. Missing is the required property proposal [0], so currently the choice is between having everything be optional, or using explicit constructors (which loses most of what is wanted here). But that does not seem like a huge difference:

    Member m = new()
    {
        FirstName = "Kelly",
        Books = new()
        {
            new() { Author = "Hohlbein, Wolfgang" },
            new() { Author = "Tchaikovsky, Adrian" }
        }
    };
Definitions:

    public record struct Book
    {
        public string Author { get; set; }
    }
    public record struct Member
    {
        public string FirstName { get; set; }
        public List<Book> Books { get; set; }
    }

[0]: https://github.com/dotnet/csharplang/issues/3630


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: