Why can't I initialize readonly variables in a initializer?

后端 未结 10 1935
渐次进展
渐次进展 2021-01-17 08:16

Why can\'t I initialize readonly variables in a initializer? The following doesn\'t work as it should:

class Foo
{
    public readonly int bar;
}

new Foo {          


        
10条回答
  •  天涯浪人
    2021-01-17 08:35

    Because you specified it is readonly. It does not make sense to specify that something is readonly then expect a write statement to work.

提交回复
热议问题