Can't create static variable inside a static method?

前端 未结 4 1105
夕颜
夕颜 2021-01-24 23:44

Why won\'t this work?

public static int[] GetListOfAllDaysForMonths()
{
    static int[] MonthDays = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,2         


        
4条回答
  •  盖世英雄少女心
    2021-01-25 00:35

    You can only create static variables in the class/struct scope. They are static, meaning they are defined on the type (not the method).

    This is how C# uses the term "static", which is different from how "static" is used in some other languages.

提交回复
热议问题