Skip to main content

Posts

Showing posts with the label What's new in C# 11

What's new in C# 11

  The following features were added in C# 11: Raw string literals Generic math support Generic attributes UTF-8 string literals Newlines in string interpolation expressions List patterns File-local types Required members Auto-default structs Pattern match Span<char> on a constant string Extended nameof scope Numeric IntPtr ref fields and scoped ref Improved method group conversion to delegate Warning wave 7   Generic Attributes: // Before C# 11: Old  feature public class TypeAttribute : Attribute {    public TypeAttribute(Type t) => ParamType = t;    public Type ParamType { get; } }   And to apply the attribute, you use the typeof operator:   [TypeAttribute(typeof(string))] public string Method() => default;   // C# 11 feature: New feature public class GenericAttribute<T> : Attribute { }   Then, specify the type parameter to use the attribute: [GenericAttribute<string>()] ...