CKTIS / C#
variables: praktická reference
variables: praktická reference: Proměnná má typ a scope, vyžaduje definite assignment a ukládá hodnotu nebo referenci.
Verze: C# language and .NET 10 reference runtime
Syntaxe
// variablesProměnná má typ a scope, vyžaduje definite assignment a ukládá hodnotu nebo referenci.
Dejte jí název popisující roli a omezte měnitelnost a scope.
Přiřazení reference objekt neklonuje a closure zachytí proměnnou.
Local musí být přiřazen před čtením; field default může skrýt chybějící inicializaci.
Úplný program skutečně používá variables; přesně očekávaný stdout je 5.
Příklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var count = 2; count += 3; Console.WriteLine(count);
Výsledek
5
Úplný program skutečně používá `variables`; přesně očekávaný stdout je `5`.