Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

variables: praktická referencia

variables: praktická referencia: Premenná má typ a scope, vyžaduje definite assignment a ukladá hodnotu alebo referenciu.

Verzia: C# language and .NET 10 reference runtime

Syntax

// variables

Premenná má typ a scope, vyžaduje definite assignment a ukladá hodnotu alebo referenciu.

Dajte jej názov opisujúci úlohu a obmedzte meniteľnosť a scope.

Priradenie referencie objekt neklonuje a closure zachytí premennú.

Local musí byť priradený pred čítaním; field default môže skryť chýbajúcu inicializáciu.

Úplný program skutočne používa variables; presne očakávaný stdout je 5.

Prí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ýsledok

5

Úplný program skutočne používa `variables`; presne očakávaný stdout je `5`.

Zdroje