/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/language-reference/operators/snippets/shared/AssignmentOperator.cs
56 строк
1 KB
Bill Wagner
Use Collection expressions for all language reference samples (#37993)
16 ноя 2023, 23:06
Не верифицирован
16 ноя 2023, 23:06
ace7aec
Код
Авторство
О чём код?
namespace operators; public static class AssignmentOperator { public static void Examples() { Simple(); RefAssignment(); } private static void Simple() { // <SnippetSimple> List<double> numbers = [1.0, 2.0, 3.0]; Console.WriteLine(numbers.Capacity); numbers.Capacity = 100; Console.WriteLine(numbers.Capacity); // Output: // 4 // 100 int newFirstElement; double originalFirstElement = numbers[0]; newFirstElement = 5; numbers[0] = newFirstElement; Console.WriteLine(originalFirstElement); Console.WriteLine(numbers[0]); // Output: // 1 // 5 // </SnippetSimple> } private static void RefAssignment() { // <SnippetRefAssignment> void Display(double[] s) => Console.WriteLine(string.Join(" ", s)); double[] arr = { 0.0, 0.0, 0.0 }; Display(arr); ref double arrayElement = ref arr[0]; arrayElement = 3.0; Display(arr); arrayElement = ref arr[arr.Length - 1]; arrayElement = 5.0; Display(arr); // Output: // 0 0 0 // 3 0 0 // 3 0 5 // </SnippetRefAssignment> } }