/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/programming-guide/classes-and-structs/snippets/private-constructors/Program.cs
44 строки
935 B
Tom Dykstra
Update snippets for NRT (#28622)
11 мар 2022, 19:03
Не верифицирован
11 мар 2022, 19:03
13fe3ed
Код
Авторство
О чём код?
//<Snippet1> class NLog { // Private Constructor: private NLog() { } public static double e = Math.E; //2.71828... } //</Snippet1> //<Snippet2> public class Counter { private Counter() { } public static int currentCount; public static int IncrementCount() { return ++currentCount; } } class TestCounter { static void Main() { // If you uncomment the following statement, it will generate // an error because the constructor is inaccessible: //<Snippet3> // Counter aCounter = new Counter(); // Error //</Snippet3> Counter.currentCount = 100; Counter.IncrementCount(); Console.WriteLine("New count: {0}", Counter.currentCount); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } // Output: New count: 101 //</Snippet2>