Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

variables: practical reference

variables: practical reference: A variable has a type and scope, requires definite assignment, and stores a value or reference.

Version: C# language and .NET 10 reference runtime

Syntax

// variables

A variable has a type and scope, requires definite assignment, and stores a value or reference.

Give it a role-describing name and limit mutability and scope.

Assigning a reference does not clone the object, and a closure captures the variable.

A local must be assigned before reading; field default can hide missing initialization.

The complete program actually uses variables; its exact expected stdout is 5.

Examples

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);

Result

5

The complete program actually uses `variables`; its exact expected stdout is `5`.

Sources