Stefan Ram
2017-04-02 20:34:09 UTC
I am reading the C# Language Specification Version 5.0,
where it is written:
»Through const declarations it is possible to declare
constants of the simple types (§10.4). It is not
possible to have constants of other struct types, but a
similar effect is provided by static readonly fields.«.
But why does the following program compile here?
(String is /not/ a simple type, it's a class, according
to the C# Language Specification Version 5.0.)
Program.cs
public static class Program
{ public static void Main()
{
const string lkw = "Lastkraftwagen";
global::System.Console.WriteLine
( $"Ein {lkw}-Fahrer lebt in seinem Fahrzeug." ); }}
transcript
Ein Lastkraftwagen-Fahrer lebt in seinem Fahrzeug.
where it is written:
»Through const declarations it is possible to declare
constants of the simple types (§10.4). It is not
possible to have constants of other struct types, but a
similar effect is provided by static readonly fields.«.
But why does the following program compile here?
(String is /not/ a simple type, it's a class, according
to the C# Language Specification Version 5.0.)
Program.cs
public static class Program
{ public static void Main()
{
const string lkw = "Lastkraftwagen";
global::System.Console.WriteLine
( $"Ein {lkw}-Fahrer lebt in seinem Fahrzeug." ); }}
transcript
Ein Lastkraftwagen-Fahrer lebt in seinem Fahrzeug.