/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/programming-guide/classes-and-structs/snippets/instance-constructors/widgets/Program.cs
37 строк
907 B
Bill Wagner
add primary constructor attribute (#37728)
25 окт 2023, 22:26
Не верифицирован
25 окт 2023, 22:26
c15f29e
Код
Авторство
О чём код?
// See https://aka.ms/new-console-template for more information Console.WriteLine("Hello, World!"); // <BasePrimaryConstructor> public class NamedItem(string name) { public string Name => name; } // </BasePrimaryConstructor> // <DerivedPrimaryConstructor> // name isn't captured in Widget. // width, height, and depth are captured as private fields public class Widget(string name, int width, int height, int depth) : NamedItem(name) { public Widget() : this("N/A", 1,1,1) {} // unnamed unit cube public int WidthInCM => width; public int HeightInCM => height; public int DepthInCM => depth; public int Volume => width * height * depth; } // </DerivedPrimaryConstructor> public class MyAttribute: System.Attribute { } // <PrimaryConstructorAttribute> [method: MyAttribute] public class TaggedWidget(string name) { // details elided } // </PrimaryConstructorAttribute>