Why can't we declare var a = new List at class level?

前端 未结 5 2095
醉梦人生
醉梦人生 2021-01-18 23:27

I know we cannot do this at class level but at method level we can always do this.

var myList=new List // or something else like this
<         


        
5条回答
  •  庸人自扰
    2021-01-18 23:33

    It's not as simple as implementing var in a method since you also have to take into acccount different modifiers and attributes like so:

    [MyAttribute()] protected internal readonly var list = new List();
    

    What I would really have liked is a type-inferenced const!

    public const notFoundStatus = 404; // int
    

提交回复
热议问题