Skip to content

cotrVarStatic

Explains alternatives to static variables

Aliases:

  • cotrVarStatic
  • staticVariable
  • associatedConstant

cpp

static type myStaticVar = value;
// Access the static variable
// MyClass::myStaticVar

csharp

MyClass.myStaticVar
static Type myStaticVar = value;
// Access the static variable

dart

MyClass.myStaticVar
static var myStaticVar = value;
// Access the static variable

haskell

-- Haskell does not have static variables in the same way as imperative languages.
-- You can use top-level definitions or modules to achieve similar functionality.

java

MyClass.myStaticVar
static Type myStaticVar = value;
// Access the static variable

javascript

MyClass.myStaticVar
static myStaticVar = value;
// Access the static variable

javascriptreact

MyClass.myStaticVar
static myStaticVar = value;
// Access the static variable

perl

ourmyStaticVar = value;
# Perl does not have static variables in the traditional sense.
# Access the package variable
#myStaticVar

php

staticmyStaticVar =2;

powershell

Terminal window
# PowerShell does not have static variables in the same way as some other languages.
# You can use class variables or module variables to achieve similar functionality.

ruby

@@my_static_var = value
# Access the class variable
# MyClass.class_variable_get(:@@my_static_var)

shellscript

Terminal window
# Bash doesn't have static variables in the same way as some other languages.

swift

MyClass.myStaticVar
static var myStaticVar = value;
// Access the static variable

typescript

static myStaticVar: type = value;
// Access the static variable
// MyClass.myStaticVar

typescriptreact

MyClass.myStaticVar
static myStaticVar: type = value;
// Access the static variable