HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to C#VariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
var / constint.Parse() / ToString()
🔢 Numbers & Math
✍️ String
📚 List & Dictionary
🔀 Condition & Loop
🧩 Function
C#›REFERENCE›Variables & Types›var / const

var / const

Variables and immutable constants.

Syntax

var name = value;   //   const Type NAME = value;

Description

With var, the type is inferred from the value, and the value can change later. const is a compile-time constant and cannot be reassigned. You can also explicitly write the type (int, double, string, bool).

Example

Loading editor…

Expected output

C#
20

When to use?

General variables; use const for values that shouldn't change.

Common mistakes

  • ⚠️ Trying to reassign a const constant causes a compilation error.

Related commands

int.Parse() / ToString()
int.Parse() / ToString() →
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code