« Csharp 12 » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Aucun résumé des modifications
Ligne 7 : Ligne 7 :
public class Item
public class Item
{
{
     private string name;
     public readonly string Name { get; }
 
    public Item (string name)
    {
        Name = name;
    }
}
}


// equivalent with a primary constructor
// equivalent with a primary constructor
public class Item(string name)
public class Item(string name)
{ }
{
    public readonly string Name { get; } = name;
}
</kode>
</kode>

Version du 13 mai 2024 à 14:14

Links

Primary constructors

Cs.svg
public class Item
{
    public readonly string Name { get; }

    public Item (string name)
    {
        Name = name;
    }
}

// equivalent with a primary constructor
public class Item(string name)
{
    public readonly string Name { get; } = name;
}