/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/snippets/methods/optional1.cs
28 строк
750 B
Bill Wagner
Add params collections (#40978)
21 май 2024, 00:01
Не верифицирован
21 май 2024, 00:01
57cbe8e
Код
Авторство
О чём код?
// <Snippet21> public class Options { public void ExampleMethod(int required, int optionalInt = default, string? description = default) { var msg = $"{description ?? "N/A"}: {required} + {optionalInt} = {required + optionalInt}"; Console.WriteLine(msg); } } // </Snippet21> // <Snippet22> public static class OptionsExample { public static void Main() { var opt = new Options(); opt.ExampleMethod(10); opt.ExampleMethod(10, 2); opt.ExampleMethod(12, description: "Addition with zero:"); } } // The example displays the following output: // N/A: 10 + 0 = 10 // N/A: 10 + 2 = 12 // Addition with zero:: 12 + 0 = 12 // </Snippet22>