« Csharp 12 » : différence entre les versions
Apparence
Aucun résumé des modifications |
|||
Ligne 25 : | Ligne 25 : | ||
<kode lang='cs'> | <kode lang='cs'> | ||
// initialization | // initialization | ||
int[] a = [1, 2, 3]; | int[] a = [1, 2, 3]; | ||
List<int> l = [4, 5, 6]; | List<int> l = [4, 5, 6]; | ||
Version du 24 mai 2024 à 13:40
Links
Primary constructors
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;
}
|
Collection Expressions
// initialization
int[] a = [1, 2, 3];
List<int> l = [4, 5, 6];
// concat items from different collections with the spread element: ..e
int[] all = [.. a, .. l];
|