Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

=: practical reference

=: practical reference: = stores a value in a variable, field, property, indexer, or element and is itself an expression.

Version: C# language; verified against C# 14 reference

Syntax

left = right

= stores a value in a variable, field, property, indexer, or element and is itself an expression.

Use a single assignment; chain assignments only when their common type is obvious.

A setter or indexer can run code and throw, and evaluation order matters for a compound target.

A conversion must exist, while readonly and init restrict where assignment is legal.

The complete program actually uses =; its exact expected stdout is 7,7.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

var value = 0; var result = value = 7; Console.WriteLine($"{value},{result}");

Result

7,7

The complete program actually uses `=`; its exact expected stdout is `7,7`.

Sources