Kotlin for C# Developers

1.3. const val

const val is equivalent to const in C#. In Kotlin, a const val:

C#

const int port = 80;
readonly string schema = "https";
readonly string host;  // Class field

// Later, in the constructor
host = "kotlinlang.org";
host = "microsoft.com";  // ERROR: can only assign once

Kotlin

const val PORT = 80   // As above, type can be inferred
val schema = "https"
val host: String   // Can be a class field or local (or even global)

// Later
host = "kotlinlang.org"
host = "microsoft.com"  // ERROR: can only assign once

Next: Functions