© { JSL }
89
Text Box: Local Variables
Local Variables
Folded Corner:
·local variables can be declared const
wbut not static, and not readonly
wand const is only for simple types
wmust be initialized to compile time constant value
struct GoodExample
{
... void Func()
    {
        const int answer = 42;
        const Suit trumps = Suit.Club;
    }
}
OK
struct BadExample
{
... void Func()
    {
        const int lv = F();
        static Pair origin = ...;
        readonly Pair p = ...;
    }
}
compile
time
errors